Try Now
More in this section
Blogs RSS feed

Followup: Converting Sitefinity 4 Web Application Projects to Web Site Projects

by Josh Morales

We previously looked at converting a new Sitefinity 4 Web Application Project to a Web Site in IIS, and although this was done with the Beta release, the procedure remains the same for the official release.

However, that guide is only useful when converting a brand new Sitefinity project; one that has no custom User Controls, Master Pages, external libraries, or any other items that might need updating.

So to help users who may have existing Sitefinity 4 Web Application Projects and wish to convert them to Web Site projects, here is a quick guide using the updated SP1 version of the Sitefinity Non-Profit Starter Kit.


The initial conversion of a project is exactly the same as laid out in the previous guide. However, in that example, we opened the web site from the File System in Visual Studio, then added that project folder to IIS.

This time, we'll do things the other way around, adding the project to IIS, then opening that web site in Visual Studio

IIS Setup

Adding a website to IIS is as simple as adding a New Web Site and pointing it to the Sitefinity folder.


A more detailed walkthrough is available in the previous posts on this subject, including setting up permissions, Application Pool, and even a hostname so you don't have to access your site using an IP address.

Remember to set your application pool to run ASP.NET 4.0 as this is required by Sitefinity.

When your site setup is complete and running, open it in your browser by using the hostname you setup (if any). In my case I used http://starterkit.


At this point you've added your site in IIS, but it is still running as a Web Application and not a Web Site. Next we'll see how to use Visual Studio to convert the project.

Visual Studio Setup

Open up the solution file for the Starter Kit and notice that you have three projects, one for the Website then two more for the class libraries used for the different widgets. Select the Website project and press the Delete key (or select "Remove" from the context menu) to remove it from the solution.


Since we've already registered the website in IIS, we simply need to add a reference to it as a project in our Solution. Right-click the solution and select "Add Existing Website" from the context menu.


In the dialog that follows, you may encounter an error such as:

"To access local IIS Web sites, you must install the following IIS components: IIS 6 Metabase and IIS 6 Configuration Compatibility, ASP.NET, Windows Authentication. In addition, you must run Visual Studio in the context of an administrator account.".

Make sure you have all of these components installed, and that you are running Visual Studio as an Administrator. For more help in setting up your environment, see this article from Microsoft: Running Web Applications on Windows Vista with IIS 7.0 and Visual Studio .

Select "Local IIS" to see a list of available websites and choose the one that corresponds to the website you created.


This adds your website project to the solution, however a few more things need to be set up before the conversion is complete.

Remove Web Application Files

Since Web Application Projects are compiled applications, they have a number of additional files, such as the *.designer.cs and global.asax.cs that need to be removed for a web site project. Begin by removing any designer class files in the project (note that these are not the same as the DesignerTemplate files).


Next delete the compiled binary for the Web Application. This are in the bin folder and usually has the same name as the original project.


The global.asax file must also be modified. In Web Application Projects, it uses a code-behind model for adding custom code. However Web Sites generally use a single file, with the script code inline.

The easiest way to do this is to delete the existing global.asax file and add a new one from the context menu.


Note: if your existing global.asax file has custom code (which Sitefinity does), the best thing to do is copy the code from the .cs file and paste it into the new one that you create.

Be sure that you import the namespaces required for any custom code you have in your global.asax file.


App_Code Folder

While a Web Application allows you to place class files and code folders anywhere in the project, Web Sites require that any custom classes and code be defined in the special App_Code folder. This is added from the context menu for your project under Add ASP.NET folder > App_Code.


Any custom classes used in your project should be moved to this location. The Starter Kit has most of this code in the App_Custom folder. Simply drag its contents into the App_Code folder.


In the starter kit, there is also a Widget Designer class in the /Widgets/Donations folder. This too needs to be moved to the App_Code folder so that it is compiled and accessible within the Web Site.


Change CodeBehind to CodeFile

While Web Application pages, master pages, and user controls use the CodeBehind property to specify the related .cs code file, Web Sites instead use the property CodeFile. Open all items that have code files and simply rename "CodeBehind" to "CodeFile".



At this point, the conversion of the Starter Kit from Web Application Project to Web Site Project is complete, and can be built and run from the url http://starterkit, although nothing should change visually or functionally.

Future versions of the Project Manager will eventually provide you the option to create a Web Site project, but completing these few simple steps will let you to choose the development environment for Sitefinity that suits you best.

If you encounter any issues following this guide, or have any questions, comments or suggestions, please visit our Sitefinity discussion forums and share your experiences with us!

Leave a comment