Microsoft ASP.Net Web Application vs Website

Introduction:
A Web application is an application that can be hosted on a web server and can be accessed from any machine that lies in the intranet or internet which has the web browser to render and display the web pages in that application.

With the help of Visual studio 2012, the web application can be created by using two different templates provided. One is by using “New Website” template and another is by using “New Web Application” template. This document is basically to compare and contrast the features of using these templates.

How to Create a New Web Application Project:

  • In Visual Studio, Select new “project “option from file menu as shown below:

New Project

New Project

 

  • Once it is done you will have the following window appearing ,in that choose “Web” tab and “ASP.NET Web Application”, as shown below :
ASP.NET Web Application

ASP.NET Web Application

How to Create a New Web Site:

  • In Visual Studio 2008, Select new “Web Site” option from file menu as shown below:
Web Site

Web Site

  • Now you can choose “ASP.NET Web Site” from the window that appears as shown below :
ASP.NET Web Application

ASP.NET Web Application

Point of Difference-: 

Web Application vs. Web Site:

Comparison 1:
There is an option to specify the File type during the creation of the “Web Site” project(File system, FTP, HTTP).But in case of “Web Application” you need to select the  type (File system, FTP, HTTP) at the time of publishing the Project.

Web Site:
When the ASP.NET web site template is selected, it would help to create a website that might be held in the file system or a website that can be hosted in the local web server (IIS) directly by specifying some URI and choosing the Location as HTTP or as FTP site.

1.  Creating a new web site with target location as File System:

File System

 

Once we choose Location as “File System” and click the browse button, a new window will open as shown below:

New File System

  • You can choose the File System tab and create a new Folder (if needed) in any desired location.
  • Once the Open button is clicked, the new web site will be ready for designing.

2. Creating a New Web Site with Target Location as HTTP:
To create a new web site with target location as HTTP, open Visual Studio in “Run as Administrator” mode, so that the web site can be deployed on the local web server directly.

  • Once the Location is chosen as HTTP and the browse button is clicked, new window will open as shown below :

HTTP

 

 

  • Choose the Local IIS tab and create a new virtual directory in any location as desired and then click the icon (pointed by the arrow in the above figure ) to create the new virtual directory
  • Once the Open button is clicked, the new web site will be ready for designing.

3. Creating a new web site with target location as FTP:

  • Once we choose Location as “FTP Site” and click the browse button a, new window will open as shown below :

FTP Site

 

  • Choose the “FTP Site” tab and specify the server and directory details
  • Once done, click the Open button and the new web site will be ready for designing.

Web Application:
When the Web Application template is used for the creation of a web application, it would appear as below.

Web Application

 

In the above snapshot you can find that there is Location option which will give the desired location for placing it as file system.

Publishing the Web Application:
When the application created using “Web Application” template needs to be published in a server, right click on the project in solution explorer and select “Publish” as shown below,

Publishing the web application

 

Web Application1

In the above snapshot you can find that at the time of publishing we have the option to fix the target location (HTTP, FTP, File system) as shown in the above snapshot.

Comparison 2:
There is a bin folder in the case of “Web Application” and when the application is built, a DLL file would get created and placed in the bin folder but in case of “Web Site” no such file gets created.

The below screenshot shows the DLL file that gets created, in the case of “Web Application”.

Comparison 2

Note: In case of web Site bin folder is created when we publish a website and dll is created when we publish the website project.

Comparison 3:
When running the application in the ASP.NET Development Server, note the changes in the URL

1. In the case of web site the URL would be as follows:
http://localhost:<portnumber>/Websitename/Default.aspx
Please find the screenshot below:

Comparison 3

2. In case of Web application the URL would be as follows

http://localhost<portnumber>/Default.aspx
Please find the screenshot below:

Comparison 4

Comparison 4:
The option to select the master page

  1. In the case of “Web Site” when a “New Web Form” item is added there is an option to select the master page to which the newly created page should adhere to, as shown below:

Comparison 4-1

2. But, in the case of “Web Application” when “New Web form” is added there will be no option to select the “Master Page” as shown below:

New Web form

Note: In case of web Application we can add the master page/content page by clicking on new item and then select the master page from the list of templates.

Comparison 5:
Variation with respect to adding a new folder

Right click on the project in solution explorer to add new folders to your application.

  1. In the case of Web Site , the available folders would be as shown below

Comparison 5

2. In the case of Web application, the available folders would be as follows:

Comparison 5-1

The App_Code folder and Bin folder will not be present in the web application. The bin folder would be added to the solution by default, hence there is no need to include it explicitly and hence that folder is not present. Whereas, if the App_Code folder is to be added to the web application, it can be done by adding a new folder and renaming it as App_Code.

Comparison 6:
During compilation “Website” follows ASP.NET 2.0 compilation model where as web application follows ASP.NET 1.1 compilation model.

What is ASP.NET 1.1 Compilation?

In this model of compilation the application is compiled to a single .dll file which is placed in the bin folder. When the application is requested for the first time by the client the .dll file is copied to a Temporary ASP.NET Files folder.  It is then recompiled into executable code called as JUST-IN-TIME COMPILATION .Hence the first request of the application faces little bit delay in getting the response.

Find below the snapshot showing the code behind file in the case of ASP.NET 1.1 Compilation:

ASP.NET 1.1

 

What is ASP.NET 2.0 Compilation?
In this model of compilation, the application compiles into one or more .dll files inside the Temporary ASP.NET Files folder when the request for the first page is made. These .dll files are placed in a sub folder with a name that is created randomly.
E.g.: c:\Windows Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET.Files\……..\340b09f8\e47ddh097

Find below the snapshot of Web Site Code beside file Model which uses ASP.NET 2.0 compilation

ASP.NET 2.0 Compilation

Comparison 7:
A separate designer file with a partial class exists in Web Application whereas no such file exists in Web Site. 

Web Application :

Web Application 5

There is a partial class with the same name found both in “<PageName>.aspx.designer.cs” file and “<PageName>.aspx.cs” file. Find below the snapshots of both the files containing the same partial class.

<name>.aspx.designer.cs file:

image1

<name>.aspx.cs file:

image2

Here, during the compilation both the partial classes will be merged together and executed as a single class. For example, here it would be “_Default” class.

Website:
Where as in the case of web site, there will not be any explicit designer file.

image3

Comparison 8:
In the “Website”, in the property pages there is an option “Allow this precompiled website to be updateable” to specify that the contents of the web page (.aspx page) are not to be compiled into an assembly. If this option is selected, the markup will be left as such which allows the modification of source as well as the code behind file even after pre-compiling the web site and deploying it.

Comparison 8

In the “Web Application”, there is no option like this.

Comparison 9:
In the case of “Web Application” a solution file is created (with the extension .sln) in the same location where the application is created, where as in the case of “Web Site” a solution file is created in a default location (e.g.

c:\Users\<UserName>\Documents\Visual Studio 2008\Projects\<Application>)

 

Note-This article targets the Visual Studio 2012 however it is valid for earlier version of the Visual Studio as well including 2008,2010.

 

Written By: Rahul Gupta, Software Engineer, Mindfire Solutions

Advertisements

Posted on June 30, 2014, in ASP.Net, C#, MVC and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: