Which web project model should I choose?
Starting with Visual Studio 2005, Microsoft introduced a new type of web project known as the Web Site project. A Web Site project is a radically simplified version of the more complex Web Application project. For instance, a Web Site project has no project file: in a Web Site project, the file system is the project.
Although Web Site projects are pleasingly simple on the surface, so many limitations were inherent in the file system model that developers soon demanded the old Web Application model back. And Microsoft evidently thought the issue was important enough to warrant action because, as of Visual Studio 2005 Service Pack 1, we can choose between two different web project models:
* Web Application project
* Web Site project
Selecting a project model is one of the first things you’ll need to do on any .NET web project.
Solution
Choice is good. But to make an informed decision, you’ll need to understand the differences between these two project models. This is an important choice that will have many repercussions for your project, so you should be familiar with how both models work.
Web Site Projects Versus Web Application Projects
Let’s take a moment to investigate the differences between the two project models.
*
Web Site projects are special cases. They do not behave like any other project type in Visual Studio.
*
Web Application projects have a project file. Web Site projects do not.
*
Web Application projects compile into one monolithic assembly DLL; to run and debug pages, the entire project must be compiled every time. Web Site projects compile dynamically at the page level; each page can be compiled and debugged independently.
*
Web Application projects are deployed “all at once,” as a single DLL, along with necessary static content files. Web Site projects are deployed as a set of files, each of which can be updated independently.
Each project type has its strengths and weaknesses, and Visual Studio 2005 will continue to fully support both project types, so either is a valid choice.
That said, web forums are overflowing with complaints about, and criticisms of, the Web Site project model. I’ve experienced enough problems with the Web Site project model myself to avoid using it. And there’s definitely a reason why Microsoft did such a quick about-face and retrospectively added support for Web Application projects with the release of Service Pack 1.
The Web Site project’s complete reliance on the file system as its statement of record makes it a little too “magical” for its own good, at least in my opinion. For example, the only way to exclude a file from a Web Site project is to rename it with the .exclude file extension. In a Web Application project, a file can be easily excluded—we simply remove the reference to it from the project file.
In general, I recommend that you avoid the Web Site project model. If you’re starting a new project, you should choose the Web Application project by default. Web Sites seem like a good idea on paper, but in practice, they’re too simplified and, ultimately, too limiting.
That said, there are a few cases in which the Web Site project type remains the best option:
*
The Express editions of Visual Studio do not support the Web Application project type. So if you’re using Visual Web Developer Express Edition, or planning to share code with developers who only have access to this tool, you should use Web Site projects.
*
For small, demonstration projects, the Web Site model is often more appropriate than a full-blown Web Application. If your project is simple, choose the simple Web Site project type.
Creating Web Projects
The process you’ll use to create a web project will depend on the type of project you need.
Creating a Web Site Project
Web Site projects are the default web project type in Visual Studio 2005 and (Visual Web Developer 2005 Express Edition). To create a new Web Site project, open the File menu and select New > Web Site…, as I’ve done in 1.1 “Creating a new Web Site project in Visual Studio”.
Next, you’re presented with the New Web Site dialog, which lets you choose where you want the Web Site project to be stored—either on the local file system, or in a remote location via HTTP or FTP, as 1.2 “Choosing the location of our new Web Site project” shows.
Click OK to create the project. Once you’ve done this, the name of the solution displayed in the Solution Explorer reflects the location of the solution in the file system,
If we right-click the solution and select Properties, the Web Site project’s properties are displayed,
Web Site project properties are radically different from the properties for every other Visual Studio project type. Only a small subset of the options you’d expect to be here are present.
Creating a Web Application Project
Warning: Visual Studio 2005 Service Pack 1 Required!
You must have Visual Studio 2005 Service Pack 1 or later to create a Web Application project. If you’re wondering why you can’t create or open Web Application projects, you probably haven’t installed Service Pack 1 yet, or you may be running the free Visual Web Developer 2005 Express Edition.
Use the File > New > Project… menu to create a new Web Application project,
In the New Project dialog, select ASP.NET Web Application, give the project a name, and select a location within the file system for the project,
Once you’ve created the Web Application project, the title of the solution will reflect the name that you specified for the project,
Note that a Web Application project has quite a few more elements than the simpler Web Site project. It has:
*
a Web.config file
*
an AssemblyInfo.cs file
*
a References folder containing a number of items
This is consistent with the way other project types—such as the Console and Windows Forms project types—work in Visual Studio. If you right-click the project and select Properties, you can browse the project properties, as 1.8 “Browsing the project properties for a Web Application” shows.
1.8: Browsing the project properties for a Web Application
Web Application projects behave almost identically to other Visual Studio project types, though Web Application projects offer the new Web tab for the management of web-specific settings.