Determine when to use the Web Site model vs. a Web Application Project
There was a post already about them, but I failed on about every question on the exam where they were involved. So this one will be a quick repost of the old facts.
A Web Application Project is very similar to a traditional desktop project. You can control references in a specialized folder, have an AssemblyInfo.cs and a project file for controlling which files belong to the project explicitly (the Web Site model does this implicitly: what’s in the folder is in the project). Also, it provides backward-compatibility, since it was the default project type for web pages in VS 2003.
You’d like to use Web Application Projects when:
- You are migrating from VS 2003.
- Need to control the names of the output assemblies.
- Need stand-alone assemblies to reference page and user control classes.
- Need a Web Application using multiple Web Projects.
- Need to add custom steps during compilation.
And in the following scenarios, you’d use the Web Site model:
- Use single-page code model.
- Prefer dynamic compilation (don’t need to rebuild site).
- Need an assembly per page.
- Want to work with the project without a project file.
A quick overview about Web Application Projects: uses explicit content, so you should set what you’d like to include in your project. It compiles all stand-alone classes and code-behind files into a single assembly, and the markup files are copied as is. However, using a Web Deployment Project, these can be compiled into a single assembly, too, but the default behavior is that they are compiled when requested.
Web Site model uses and implicit content, thus what’s in the folder, that’s in the project. It uses dynamic compilation, but you can precompile it. There are two modes: batch – which produces one assembly per folder, and fixed-names, one assembly per page/user control. The latter method increases memory usage, but creates a more maintainable solution, since it’s easy to identify the page you’d like to change.