Blog posts


  • Prevent EPiServer UrlRewrite

    November 09, 2010 | Tags: EPiServer, ASP.NET, SEO, Troubleshooting
    Sometimes it's needed to turn off EPiServers function for Url rewrite, like if you for instance writes a link-element with a canonical url (which helps search engine optimization (SEO)). The UrlRewriteProvider works as a HTTP-module, which means that it's running after your page is rendered, parsing all your Urls in a predefined list of elements and attributes.

    To prevent EPiServer's Url rewrite to occur do the following to your element:
    1) Add an id-attribute to your element
    2) Add a special EPiServer attribute to prevent the rewrite


    Original code:
    <link rel="canonical" href="the/url/not/to/rewrite" />

    Updated code:
    <link rel="canonical" id="canonical1" <%=EPiServer.Web.UrlRewriteProvider.UrlPreventRewriteAttribute %>="true" href="the/url/not/to/rewrite" />

  • Get all values from CheckBoxList in C#

    November 04, 2010 | Tags: C#, LINQ, Snippet
    This is a class that add an extension to the CheckBoxList class to return a comma separated string with all the selected values.

    You call this function by the following:
    string mySelectedValues = myCheckBoxList.GetSelectedValues();
    The class to place somewhere in you project (remember to add a using-reference to any class you want to call this function from:
    public static class CheckBoxListExtension {
    public static string GetSelectedValues(this CheckBoxList checkBoxList) {
    string retval = string.Empty;

    try {
    foreach (ListItem item in checkBoxList.Items) {
    if (item.Selected) {
    retval += item.Value + ',';
    }
    }
    retval.TrimEnd(',');
    }
    catch (Exception) {
    }

    return retval;
    }
    }

    Or the same code if LINQ is your poison:
    public static class CheckBoxListExtension {
    public static string GetSelectedValues(this CheckBoxList checkBoxList) {
    string retval = string.Empty;

    try {
    retval = checkBoxList.Items.Cast<ListItem>().Where(item => item.Selected).Aggregate(retval, (current, item) => current + (item.Value + ','));
    retval.TrimEnd(',');
    }
    catch (Exception) {
    }

    return retval;
    }
    }

  • EPiServer: Get unpublished children too

    October 29, 2010 | Tags: EPiServer, C#, Snippet
    DataFactory.Instance.GetChildren(myPageLink) only returns the children which are published. If you also want to get the pages that aren't yet published you should use the LanguageSelector-parameter which utilizes language fallback to return all children published or not. It doesn't matter if your EPiServer site is in one language only, the following will return published and unpublished children:
    PageDataCollection children = DataFactory.Instance.GetChildren(myPageLink, LanguageSelector.AutoDetect(true));

  • Microsoft Dynamics CRM Framework for EPiServer available for download

    October 27, 2010 | Tags: EPiServer, Microsoft CRM, Open source
    A Microsoft Dynamics CRM Framework for EPiServer has been released as open source by Karoline Klever and is available for download at http://crmframework.codeplex.com/

    You'll also find the documentation at Codeplex.

  • Regenerate aspx.designer.cs file

    October 26, 2010 | Tags: ASP.NET, Troubleshooting
    Seems like the connection between your asp and asp.designer.cs file has stopped working? Here's a two step guide how to regenerate it.

    Within the Visual Studio:

    1) Remove your aspx.designer.cs file

    2) Right click on your aspx file and select "Convert to Web Application"


    This should add the aspx.designer.cs back and up to date.

    If you get an error saying:
    "Generation of designer file failed: The method or operation is not implemented."

    Try close Visual Studio and then reopen your project and do step number two again.