Sep 12

I am currently converting a lot of  legacy ASP.NET Web Sites over to ASP.NET Web Application Projects.  The reason for doing this is so I can make my NUnit Test project reference my Web Application Project.  There are various discussions about ASP.NET: Web Site vs. Web Application, but for me it was solely for testability purposes.

In Visual Studio 2008, the process to convert a Web site over to a Web Application project is relatively painless:

  • Create a Web Application project, File -> New -> Project,  then select “ASP.NET Web Application”.

New WebApplication Project


  • Once the project is created, delete all files apart from the project itself.
  • In Visual Studio ensure both the Web Site and Web Application projects are open.
  • Using Visual Studio select all the files from your Web Site and copy them to your Web Application project.
  • Then select your Web Site, right click -> Property Pages and select references.  Make a note of all the references.
  • Select your Web Application project and add all the references you made a note of in the previous step.
  • Finally select your Web Application project, right click and select Convert to Web Application.
  • Optional rename the Old_App_Code folder to anything but App_Code, I usually rename it Infrastructure.

You should now be able to build your application as usual.  The only problem I’ve found so far is; if you have been loose with your namespaces in the App_Code folder, you will need ensure you use namespaces as you would normally, then add the using directive in the normal way to your pages.  The reason for this is in a Web Site anything in the App_Code folder is automatically available to all ASP.NET pages, regardless of the namespace!

Update: I ran into one other issue when using ASP.NET Profile in Web Application Projects, unfortunately when using a Web Application Project the proxy class that is created automatically to wire up your custom fields doesn’t get created (as it does when using App_Code in a Web Site).  The proxy class is used to access strongly-typed properties; representing the Profile fields you defined in your web.config.   Luckily Joe Wrobel has a excellent solution for this problem, thanks Joe! Don’t forget to add WebProfile.cs to your project (the MSBuild task creates this for you, in the root folder of your project).

7 Responses to “Converting a ASP.NET Web Site to a Web Application Project”

  1. aspfanboy says:

    Excellent article thanks, found the information about Profiles when using a project very useful.

  2. […] Converting a ASP.NET Web Site to a Web Application Project. […]

  3. lynda says:

    Thank you very much for this post. I want to convert my website project to web application project for the sole purpose of doing unit testing also. I am new to and unit testing. My current code files in App_Code don’t have a namespace. If I convert my website project to web application project: How to add namespace to my current classes of App_Code? Do I need to go inside of each file add namespace for each class? If I rename the App_Code to new LibaryClass in converted WAP project, should I gave it the same namespace name? Thank you very much!
    Best Regards

    • DalSoft says:

      Yes all you need to do is move the .cs files to a new folder and add a namespace to them (just after your using statements). With regards to naming the folders and namespaces that’s up to you, generally I try to make it obvious for example, I use the namespace DalSoft.Infrastructure and a folder named Infrastructure for code that is for the Infrastructure of my site. You may also want to put reusable code in there own projects, this allows you to start creating your own reusable libraries which further promotes testability and separation of concerns.

      Hope this helps,


  4. R0man says:

    I’m using App$Code folder name for code/classes. In this case there is no problem within namespaces (they all remain

  5. Chris says:

    Hi, Do you have any instructions on converting a Web Application to a Web Site. I have complete a project and realized that I should have developed it as a website as I need to deploy it on another machine.


    • DalSoft says:

      Going from a web application to a web site shouldn’t be a problem, just create a new web site and copy the files from the web application project.

      However it is just as easy to deploy a web application project as a web site.

Leave a Reply

preload preload preload