|
|
|
|
Visual Studio Web Application Vs Web Site Model
ASP.Net tutorial by Barbie Hocking ©2009
In Visual Studio 2001 and 2003, the web project model was a Web Application. Visual Studio 2005 introduced the Web Site model which initially completely replaced the Web Application. Because many customers could not practically convert their Web Applications into Web Sites, VS 2005 reinstated Web Applications as an add-in. In VS 2008, both Web Sites and Web Applications are included as standard projects.
Confusion on the differences between the two models abound. Forums often have questions posted concerning a Web Site and answers are posted that are accurate - for a Web Application. This is akin to comparing apples to oranges.
Each model has its pros and cons. This article will highlight the major differences between the two.
|
Web Application |
Web Site |
Advantage
Goes To |
| Build Assemblies |
Single Assembly |
Multiple Assemblies |
Draw |
| Dynamic Compilation |
No |
Yes |
Web Site |
Stand-alone Page and User Control Classes
Provides ability to cross-reference controls, public methods, and public properties |
No |
Yes |
Web Application |
|
Build Assemblies
The Web Application model builds into a single assembly. The Web Site model builds an assembly for each directory. The single vs. multiple assemblies paradigm is what drives the "Dynamic Compilation" and "Stand-alone Page and User Control Classes" features.
When a Web Site is published, all code within the same directory is compiled into a uniquely named dll. The publish process inserts the dll name into the master page, web form, or user control definition. For example:
» All web entities residing on the root are compliled into App_Web_jrj48mxx.dll.
» The default.aspx page which resides on the root is updated to inherit this dll -
<%@ page language="C#" inherits="_Default, _Web_jrj48mxx" %>
All of a Web Site's class objects and interfaces must reside within the App_Code directory. They are compiled into the App_Code.dll and thus are accessible throughout the application.
Deployment is an important consideration when choosing which web model to use. A Web Application contains one assembly. A Web Site contains mutiple assemblies and those names will change with each new deployment.
Dynamic Compilation
From a developer's perspective, the biggest advantages of using the Web Site model is the Dynamic Compilation feature. This allows coding changes to be applied to web entities while the application is running. Developers no longer have to stop the application, apply updates, rebuild, and restart the application.
The advantage of faster development time cannot be over-emphasized. The time required to step through pages to reach altered code after an application is restarted can be quite substantial. In the Web Application model, products such as wizards force developers to muddle thru multiple pages, each of which require data entry and experience SQL performance overhead, before the coding updates can be tested. With the Web Site model, there is no need to end the debug session. Within the active session, code updates can be applied and saved. Refreshing the web browser loads the updated code. Eureka! The developer is testing the updated code on the desired page with the desired test conditions. Note, updates to class libraries still require that the debugging session be ended.
Stand-alone Page and User Control Classes
In the Web Application model, class objects are easily referenced between web entities. One of the biggest disadvantages of the Web Site model is that web pages and user controls are no longer stand-alone classes. This is because web entities potentially reside in separate assemblies. So, communication between a Web Site's master pages, web forms and user controls is not straightforward. However, there are coding solutions. Once you learn the techniques, you can continue to reuse their approach. Refer to the Web Site Techniques and Interface Techniques tutorials which outline various solutions.
Conclusion
Even though the Web Site model has cumbersome master/parent/child communication and can introduce deployment issues, I give the overall advantage to the this model. All development shops need their software delivered yesterday. The ability to apply software updates on the fly within a debugging session saves an incredible amount of time. That translates into you getting your life back! |
|
|
|
|
|
|