Converting a ASP.NET 2.0 Website to a Web Application Project

.NET, ASP.NET 2.0, Technical stuff, Website
See comments
Version 1.12 of my PhotoAlbum web application was built using the "New website" menu in Visual Studio 2005. This creates a website project, which I was curious to try, as I didn't have any experience with it. I come from ASP.NET 1.1, where the model is very different. For example, you precompile the website before deploying it (in ASP.NET 2.0, it's not compulsory; you can deploy the ASPX files together with the CS files and it is compiled on demand). Also, in ASP.NET 1.1, you have total control on the DLL, for example you can set the name, assembly information (version, company name, etc...). In the 2.0 website model, the project properties are very limited. Even if you precompile the website before deploying it, you don't have that kind of control over the DLL. Thankfully, Scott Guthrie and his team at Microsoft released already a few months ago a Web Application Project (WAP) template for Visual Studio. This template allows the same kind of control over the web project as in 1.1, but with all the added features of 2.0. For a web application developer, it's a life saver.
The WAP makes the web application much closer to an application than to a website. The 2.0 website model is quite OK for a website, where the content is more important than the functionality, but is not sufficient (IMHO) for an application, where versioning, for example, is crucial. The same application may be deployed on different sites, with different versions, and it's really important to be able to differentiate the versions easily. Also, the application is a product, so naming and setting properties is very important, as a part of the product identity.
Another big problem with the 2.0 website model is source control. Everything under the website root is considered being part if the project. This can be a problem for sites with big content (many pictures, big videos, big binary documents, etc...) because if you add the solution to the source control system, everything under it is added. This leads to huge source control DBs and is not efficient. With the WAP, however, you can include or exclude files to the project as you want. In the PhotoAlbum, typically, the CSS, JavaScript, ASPX, HTML and CS files are part of the project, but the image files are not (they're here only for test purposes, and of course in the deployed application). This way, the source control remains manageable.
WAP with included and excluded files and folders
WAP with included and excluded files and folders
For the PhotoAlbum, I had to come to the conclusion that the 2.0 website model is not adapted, and I decided to convert it to a Web Application Project. It's actually very easy, but one point must be observed: In 1.1 web apps, I used to place code-behind files manually in an "App" folder. This made deployment easier, because you could make rules like "All files under the root must be copied to the web server, and all folders starting with a non-capitalized letter". For instance, the folders "script" and "layout" would be copied, but the "App" folder wouldn't. Of course, this was not automatic, and you had to manually set the "Inherits" attribute of the "Page" directive to the correct path.
<%@ Page
Inherits="GalaSoftLb.Web.PhotoAlbum.WelcomePage" %>
Page directive pointing to non-default classes and locations
In WAP 2.0, however, it's not possible anymore. In ASP.NET 2.0, the compiler automatically generates a "designer.cs" file, using the partial class feature which was not existing in 1.1. In this generated partial class, the web controls are declared, so that the developer doesn't have to manually add them to the code-behind (that was a tedious task in 1.1). Unfortunately, the compiler is not able to do that if the code-behind file is not where it is expected, and this is in the web application root (together wth the ASPX file).
Well, it's not that bad, because you can now automatically publish the web application (using Build/Publish in Visual Studio 2005), and only the files needed on the server are actually copied. But still, and even though the "designer.cs" makes the developer's life easier, it bothers me a little that I cannot organize my source code files like I want.
Anyway, I guess I must stop being a maniac for now, and just leave the code-behind files in the root.
Previous entry | Next blog entry

Responses to “Converting a ASP.NET 2.0 Website to a Web Application Project”

  1. Says:

    Converting an ASP.NET 2.0 Website to a Web Application Project

  2. Danny Says:

    Another solution to managing your code in a hybrid manner between your two framework versions above is to allow the code-behind to reside with the page/control, but simply inheret from the app_code directory in that class.

    public class welcome : class_welcome

    where class_welcome exists in your app_code share.

Comments for Converting a ASP.NET 2.0 Website to a Web Application Project