EPiServer and the Visual Web Developer 2008.

by: Fredrik Tjärnberg

I've heard the question "Can we use the Web Site model of Visual Studio to build our EPiServer solution" a couple of times and up until now the answer to this question have been "No!". The reason for this is that there is no way to exclude files and folders like the UI and Util folder from being "treated" by Visual Studio in this model without excluding them from the site entirely.

However, ASP.NET 2.0 introduced a feature called Virtual Path Providers that EPiServer use and extend a bit in EPiServer CMS 5. This feature makes it possible to "plugin" virtual file systems on configurable locations in the application. The main reason for using this in EPiServer is for exposing file systems to the filemanager but it turns out that there are other situations where these VPP's come in handy. For instance, it makes it possible to hide EPiServer application folders (UI, Util, WebSerices) for Visual Studio but still exposing them to the ASP.NET site... and that is basically what we need to support the Web Site model.

Setting up the project

Here's what you do:

  • Create a EPiServer CMS 5 SP1 project from Visual Studio 2005.
  • Close Visual Studio.

...Now, to be brave and make things a little more interesting, I am going to show the steps for doing this in Visual Studio 2008 (and if your'e both cheap and brave try Visual Web Developer 2008 Express Edition)...

  • So, open the flavour of Visual Studio that suites you. Note for Vista users: I have to run VS as administrator (right click the VS icon and select Run as administrator) to be able to debug this site for some reason that I haven't been able to crack yet.
  • Select "Open Web Site..." and locate the project directory you just created.
  • Visual Studio 2008 has this wonderful new feature called "multi targeting" which lets you choose which version of the framework that you want to use for you project... So, when you open the folder as a web site Visual Studio will prompt you with the following question:

    image
  • Choose "Yes"...we have already decided to be brave right?... and besides, what could possibly go wrong?!
  • Select the project root in the solution explorer and pull up its properties (F4)
  • Set "Use dynamic ports" to False.
  • Set the port number to whatever port number is used in the web.config. (default 6666)
  • Now get rid of the csproj and csproj.user file from the solution explorer.
  • Move the application folders (UI, Util and WebServices) to a location outside the application directory. For this example i used a directory in the user directory that I called ApplicationFiles.
  • Add a VirtualPathNativeProvider configuration for each relocated folder in Web.config. Set the physicalPath attribute to wherever your UI, Util and WebServices files are located.
  • <add 
     showInFileManager="false" 
     virtualName="UI" 
     virtualPath="~/UI/" 
     physicalPath="%USERPROFILE%\ApplicationFiles\5.1.422.122\UI" 
     name="UIFiles" 
     type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />
    <add 
     showInFileManager="false" 
     virtualName="Util" 
     virtualPath="~/Util/" 
     physicalPath="%USERPROFILE%\ApplicationFiles\5.1.422.122\Util" 
     name="UtilFiles" 
     type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />
    <add 
     showInFileManager="false" 
     virtualName="WebServices" 
     virtualPath="~/WebServices/" 
     physicalPath="%USERPROFILE%\ApplicationFiles\5.1.422.122\WebServices" 
     name="WebServiceFiles" 
     type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />

  • Now, you should be able to start the application with or without debugging and you will eventually get the directory listing of the root folder as shown below. This is because we haven't added a default document for the site yet.
    image 
  • Now to prove that EPiServer actually works in this configuration, add UI/Edit to the address bar and press "Enter" and hopefully, you will be asked to login to EPiServer

    image 
  • Logging in using your windows username and password will bring you to EPiServer edit mode. Served from outside the application root!
    image 

We are now finished with setting up the site configuration to be used with the Visual Studio web site model. Using this model provides a number of features not available for the web application project that we normally use for EPiServer development such as "compile on the fly" type of development, support for Visual Basic.NET (if you're more into reading your code than writing it) and even mixed language development. We have also seen that this is all possible using the Visual Studio 2008 product family.

Creating a page template

The next step for the site is ofcourse filling it with page templates, user controls and master pages. Unfortunately, the item templates for creating these items for EPiServer is not available in the web site model but here's what you do to add a for instance a page template for the start page.
  • Select "Add new item" on context menu for the project node in solution explorer.
  • Select "Web Form", name it "default.aspx" and select your preferred language and .
  • Add some markup for your page template.
  • Open the code view and change so that the generated class inherits from a EPiServer.PageBase deriving class as below:

    Partial Class _Default
        Inherits EPiServer.TemplatePage

    End Class

  • Since the page template was created using the standard web form template we need to register the template manually in Admin mode and provide the properties that we need for the template.
  • When that is done we're all set to create the start page of the site in Edit mode and browse the site!

Enjoy!

24 January 2008


Comments

  1. Cool! This makes the project folder a little bit cleaner. In my opinion the ideal sollution should not have any EPiServer files in the web folder at all (except for the binaries). It would feel good if the only thing there is your own templates. Fredrik, INEXOR AB - http://blog.fredrikhaglund.se
Post a comment    
User verification Image for user verification  
Fredrik Tjärnberg

About me

Developer and Team Lead for the backend development team with an unnatural interest in developer tools such as Visual Studio and MSBuild and Team Foundation Server.


Syndications


Archive


Tag cloud

EPiTrace logger