How to Configure and Deploy Website Using ASP.NET

MinalS's Avatar author of How to Configure and Deploy Website Using ASP.NET
A step by step guide on how to configure a web server for deployment and then actually deploy a a complete website..

Configuring a Web Server for Deployment



Web services are used to accept requests from Web browsers and respond accordingly. To enable the web services to respond to the web server, we need to configure them. The configuration of the web service involves the following tasks.
  1. Creation of Virtual directory
  2. Defining a web application URL
  3. Registering the ASP.NET file mappings
1. Creation of Virtual directory

In the development phase of the application, the web application is saved in a folder on a computer on which the development is performed. After the development is completed, the application needs to be deployed on the web server. When you deploy the application on the server such as IIS, user needs to create a directory on the web server. The contents of the directory must be web pages, images, user controls, and data source files of the application. The directory is called virtual directory.

A virtual directory is created such that the user does not get the direct access to the web application folder on the host computer. The security id maintained as user or client cannot manipulate the data.

It exposes the components of a web application to the remote clients and allows them to access the web application through web browsers. When the user requests for the web page in a virtual directory, the web server searches the page into the corresponding physical directory on the host computer. After locating the page, the server send it back to the client.

Configuring the Application Pools

After the creation of the virtual directory, user can configure the application pool for the application. The pool contains one or more applications and allows the user to configure the isolation levels between different web applications.

User can configure the application pools of the web application by using the IIS manager. User needs to right click the virtual directory that is created for the web application and select the properties option. The isolation level for the application can be set by selecting the option from the Application Protection drop down list.



The properties dialog box provides the following application protection options:
  1. Low (IIS Process): The application that are configured to run under this application protection run in the Inetinfo.exe. It hosts the IIS core processes. If the application fails, it might stop the functioning of the web server.
  2. Medium (Pooled): The applications are configured to run under the application protection share. If the application fails, the web server does not get affected. The other application running under the application protection share may get affected.
  3. High (Isolated): The applications that are configured to run under this application protection are isolated from both the Inetinfo.exe and dllhost.exe files. Hence, if the application fails it will not affect other applications or the web server.
2. Defining the web application URL

Users can access the web application by using the address in the address bar of the web browser. The address is known as Uniform Resource Locator (URL). A URL is the location of the file on the web. It is unique for each application.

To access the application, user types the URL for the application in the address bar of the web browser. It sends the request to the web server. It searches for the application mapped to the URL and sends the back to the browser.

Consider the example of the URL as http://172.22.3.203/MyWebApp/default.aspx.

In the preceding URL, 172.22.3.203 is the IP address of the web server and MyWebApp is the virtual directory. To access the web application through IP address, user needs to remember the address. It is difficult to remember the IP address. Instead of the IP address, the applications are accessed through the unique name as the domain name.

For example, the application can be accessed by the following URL.
http://www.facebook.com/Home/Friends.aspx. In the example, the www.facebook.com is the domain name for the website.

3. Registering the ASP.NET File Mappings

When multiple versions of .NET framework are installed on the same computer, each version installs the ASP.NET Internet Server Application Programming Interface (ISAPI) extension. This extension version determines which version of the CLR will be used with the particular web application.

A web application is configured to use any versions of the .NET framework that is installed on the computer. To configure the web application to use a particular version, user needs to register a script map in the Internet Information Server (IIS). A script map is the path to the ASP.NET ISAPI version used by the application.

When a user requests for a particular web page, the script map for the application directs IIS to forward the requested file to the ISAPI for processing. When the user needs to work for the particular version of the framework, user needs to update the script maps so that they can direct the request for a web page to the appropriate version of the ASP.NET ISAPI.

Deploying a Web Application



The Internet is the best medium for accessing information on any topic of concern. The information available on the internet is contained in different web applications. To enable the users to access this information, the applications need to be installed on the web server. The process of installing the web application on the web server is known as deployment.

The basic technique of deployment is the copy of the application components to the hard drive of the web server. In this process, various complements are deployed in the un – compiled form. This type of deployment has following issues:
  • The application is deployed even if it contains compilation errors
  • The source code of the application is exposed
  • The loading of the application is slow because compilation is done when it is accessed for the first time.
Precompiling a web application

Precompiling a web application involves compilation of the source code into the DLL assemblies before deployment. The advantages of the precompilation are as follows:
  • It provides fat response time because the application does not need to be compiled the first time it is accessed.
  • It helps in identifying the bugs that can occur on the web page when requested
  • It secures the source code of a web application from the users that access the application
The aspnet_compiler.exe command line tool is used to precompile the web application. This tool contains web pages, user controls, resources, and utility classes into assemblies and creates output in the form of the executable version of the application. It removes all the source an markup from the output.

To compile the website, user needs to execute the aspnet_compiler command. The sample of the command is as shown below:
Code:
aspnet_compiler –v / -p E:\MyWebSite E:\TargetWebSite
In the above example, the path E:\MyWebSite specifies the physical directory containing the source code and the path E:\TargetWebSite specifies the location where the compiled project needs to be saved.

The following lists denotes some options that can be used with the tool.
  • -v: It specifies the virtual path of the application to be compiled
  • -p: It specifies the physical path of the application to be compiled
  • -u: It specifies the exe should create a precompiled application that allows to updates of contents of the .aspx pages.
  • -c: It specifies the application to be compiled should be fully rebuilt. The already compiled components are compiled again.

Deployment Types



Deployment is the process of copying the asp.net web application from the deployment server to the server on which the application is to be executed. There are several ways in which we can deploy the application. User can deploy the application in three different ways as mentioned below:
  1. xCopy Deployment
  2. Copying a website
  3. Creating a Web Setup project
xCopy deployment is the easiest way for deployment to create copies of an application and different servers for testing purposes. For small applications, xCopy deployment is the best choice.

1. xCopy Deployment

xCopy deployment is used when user needs to drag and drop files in File Transfer Protocol, DOS Xcopy command to copy files from one location to another. A xCopy file transfer simplifies the deployment and maintenance of the Asp.NET sites as user does not need to make any registry entries. It does not require any special software on the development computer or the web server.

The steps to perform xCopy website are as mentioned below:
  1. Click ‘Start’, Select ‘Programs’
  2. Click ‘Administrative Tools’, select ‘Internet Services Manager’ option
  3. Select ‘Virtual Directory’, click ‘Properties’
  4. Navigate to the ‘Application Settings’ option, and select the ‘Application Name’ from the box, Click ‘Create’
  5. Open the website to be deployed and choose the website copy command
  6. Click connect button to display the open website dialog and choose the destination to copy website
  7. Click arrow buttons to copy the files from the source website to the remote website
Advantages of xCopy Deployment
  • It is easy, simple, quick as no registry entries and no special requirements are required
  • If the user has the authority for client and server deployment, the method is useful
Disadvantages of xCopy Deployment
  1. The deployment is done manually and hence time consuming
  2. It cannot be used for complex projects
  3. It does not provide robust installation compared to .NET deployment
  4. It does not register or verify the location of the assemblies
Copying a website

The copy website utility enables the deployment of a website quickly and easily by copying the files from the source site to the remote site. The source site is where the Visual Studio file has opened. The remote site is the site where files needs to be copied. The destination files can be any one from the following locations:
  • A file – based website
  • A local IIS website
  • An FTP website
  • A remote website
The copy website utility copies the selected files to the destination. The source file that is not compiled cannot be deployed. The type of source files that can be used are as follows:
  • ASPX files
  • Code-behind files
  • Other web files as HTML and image files
To publish a website using the copy website utility, follow the steps mentioned below:
  1. Open a website in Microsoft Visual Studio
  2. Select ‘WebSite’ > ‘Copy Web Site’ option, the following window will open

  3. Click ‘Connect’ button. The Open Website dialog box will open

  4. Select the IIS option, and open the Local Information Server page from the list of options
  5. Open the ‘New Virtual Directory’ dialog box and create a virtual directory
  6. Click ‘Browse’ button and locate the folder that contains the website to be deployed
  7. Click ‘OK’ button and the virtual directory with the specified name will open
  8. Click ‘Open’ button and select the files that needs to be copied from the source website to the destination website
  9. Save all the file in the system
  10. Exit the Visual Studio application
Creating a Setup Project

To deploy the web applications on the server, user needs to create a web setup project. The web setup project creates an installer file that contains the application, dependent files and information about the application.

The list of advantages of web setup project are as mentioned below:
  1. It automatically creates virtual directories and configures the required IIS settings
  2. If the installation is not successful, all the contents are rolled back
  3. The uninstallation process is easy for the user
The steps to create a web setup project are as follows:
  1. Open the website for which user needs to create the setup project
  2. Select the application folder in the Solution Explorer window
  3. Select Build > Build Web Site option
  4. Select File > Add > New Project option. The Add New Project dialog box will appear as shown below

  5. Expand the Other Project Types mode in the Project Types section. Select the ‘Setup and Deployment’ project type

  6. Select the ‘Setup Project’ template under the Visual Studio installed templates section
  7. Type the name of the web setup project in the Name text box and specify the location in the location combo box. Click ‘OK’ button
  8. Right Click the Web application folder, select ‘Add’ > ‘Project Output’ option.

  9. The ‘Add Project Output Group’ option dialog box appears as shown below:

  10. Select the ‘Contents Files’ option, click ‘OK’ button
  11. Right click the web setup project file in the Solution Explorer window. Select ‘Build’. The setup folder is created in the Application\Debug folder. Install the project by double clicking the setup file
shabbir like this