2010-02-05

Upgrading EPiServer to MasterPages

Initial Status:
I have already upgraded the EPiServer solution from Visual Studio 2003 / .NET 1.1 to Visual Studio 2008 / .NET 2.0/3.5. First upgraded to VS2005/.NET 2.0 by opening the projects in VS2005 and using the wizard, then converting the project to a web application. Then did the same again, opening the project in VS 2008. Everything seemed to work fine after the upgrade. So next step is to upgrade from using EPiServer:DefaultFramework to using master pages.

Next steps:
I found the (very good I might add) article: http://world.episerver.com/Articles/Items/Experiences-from-migrating-to-EPiServer-461-and-ASPNET-20/ and tried to follow the steps described from the section called “Upgrading your custom templates to ASP.NET 2.0”. However there seems to be some little information missing:

  1. In addition to changing the <@ Control … to <@ Master … you must also in code-behind change the inheritance so that the master page inherits from System.Web.UI.MasterPage in stead of EPiServer.WebControls.ContentFramework.
    This will cause some problems:
    1. If you have any references to CurrentPage, you will need to fix it. I fixed it by creating a new property on the master page called CurrentPage:

      public PageData CurrentPage
      {
          get
          {
              PageBase pb = (PageBase)this.Page;
              return pb.CurrentPage;
          }
      }

    2. Also if you are using any commands that are not prefixed and are using functionality from the previous base class you will need to fix them:
      1. Translate(…) => EPiServer.Global.EPLang.Translate(…)
        I solved this by creating a private function in the master page code-behind, which saved me from changing code in multiple places:
      2. private string Translate(string key)
        {
            return EPiServer.Global.EPLang.Translate(key);
        }

      3. GetPage(…) => EPiServer.Global.EPDataFactory.GetPage(…)
        Again I solved it by creating a private function with the same name:
      4. private PageData GetPage(PageReference pageLink)
        {
            return EPiServer.Global.EPDataFactory.GetPage(pageLink);
        }

  2. The process of converting from the 1.1 style of declaring the controls in code-behind to the 2.0 way using the .designer.cs file is not always working as is should. I had to go into the code-behind file and remove declarations of controls, and then made a slight change to the front master page file, and the saved it, so that the controls using the runat=”server” attribute were (automatically) declared in the designer.cs file. Also some events vere explicitly declared in code-behind (opposed to the new way of using “AutoEventWireup=True”. I just removed them as they were doing nothing anyway.

  3. Also had a small problem due to some additions to the asp.net control gallery and poor naming conventions. The old EPiServer Content Framework files declared a conrtol called simply “Menu”. This name crashes with the “System.Web.UI.WebControls.Menu” web control, so I just changed the name.

And now my web is up and running with EPiServer 4.51 (on VS2008) and using Master Pages (on only one page so far: default.aspx). After changing all aspx-web forms so that they use the new master page, the next step will be to upgrade EPiServer to 4.62B, and thanks to the previously linked article this should hopefully be a piece of cake.

No comments:

Post a Comment