32.1. Web Application vs. Web Site Projects

With the release of Visual Studio 2005, a radically new type of project was introduced — the Web Site project. Much of the rationale behind the move to a new project type was based on the premise that web sites, and web developers for that matter, are fundamentally different from other types of applications (and developers), and would therefore benefit from a different model. Although Microsoft did a good job extolling the virtues of this new project type, many developers found it difficult to work with, and clearly expressed their displeasure to Microsoft.

Fortunately, Microsoft listened to this feedback, and a short while later released a free add-on download to Visual Studio that provided support for a new Web Application project type. It was also included with Service Pack 1 of Visual Studio 2005.

The major differences between the two project types are fairly significant. The most fundamental change is that a Web Site project does not contain a Visual Studio project file (.csproj or .vbproj), whereas a Web Application project does. As a result, there is no central file that contains a list of all the files in a Web Site project. Instead, the Visual Studio solution file contains a reference to the root folder of the Web Site project, and the content and layout are directly inferred from its files and sub-folders. If you copy a new file into a sub-folder of a Web Site project using Windows Explorer, then that file, by definition, belongs to the project. In a Web Application project you must explicitly add all files to the project from within Visual Studio.

The other major difference is in the way the projects are compiled. Web Application projects are compiled in much the same way as any other project under Visual Studio. The code is compiled into a single assembly that is stored in the in directory of the web application. As with all other Visual Studio projects, you can control the build through the property pages, name the output assembly, and add pre- and post-build action rules.

On the contrary, in a Web Site project all the classes that aren't code-behind-a-page or user control are compiled into one common assembly. Pages and user controls are then compiled dynamically as needed into a set of separate assemblies.

The big advantage of more granular assemblies is that the entire web site does not need to be rebuilt every time a page is changed. Instead, only those assemblies that have changes (or have a down-level dependency) are recompiled, which can save a significant amount of time, depending on your preferred method of development.

Microsoft has pledged that it will continue to support both the Web Site and Web Application project types in all future versions of Visual Studio.

So which project type should you use? The official position from Microsoft is "it depends," which is certainly a pragmatic, although not particularly useful, position to take. All scenarios are different, and you should always carefully weigh each alternative in the context of your requirements and environment. However, the anecdotal evidence that has emerged from the .NET developer community over the past few years, and the experience of the authors, is that in most cases the Web Application project type is the best choice.

Unless you are developing a very large web project with hundreds of pages, it is actually not too difficult to migrate from a Web Site project to a Web Application project and vice versa. So don't get too hung up on this decision. Pick one project type and migrate it later if you run into difficulties.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.75.165