Deploying ASP.NET Applications
 
Published: 19 Oct 2007
Abstract
This article covers how to deploy ASP.NET Application in the production environment. It takes you through some of the concepts like application pool, why we need it and Configuring Application pools. At the end the author discusses some of the common problems that may arise during deployment and the possible solutions to overcome them.
by Satheesh Babu
Feedback
Average Rating: 
Views (Total / Last 10 Days): 76521/ 218

Introduction

As an ASP.NET developer, we are always focusing on learning new ideas on design and development which made us to have less knowledge on deployment of applications in production. This article targets developer community to have some of the rudimentary knowledge on deployment of ASP.NET application on IIS 6.0. After reading this article a user will be familiar in:

·         Virtual Directories and Creating it

·         Application Pools, Creating Application Pools and why it is used

·         Use of service accounts in Application Pools

·         Web.Config Settings and using Web.Config Settings for debugging errors

·         Common hindrance we may possibly face during deployment and resolutions

It is assumed that the user is logged in to the server or connected to the server through Remote Desktop Connection and the user has enough permission to do the deployment.

Preparing the application for deployment

We can use the Web Deployment plug-in for Visual studio 2005 given by Microsoft for creating Web deployment projects for 2.0 Applications, where we can compile in release mode for 1.1 applications for deployment. See the reference section for more details on Web Deployment plug-in. Copy the application to a folder location where the application needs to be deployed on the server. Make all Web.Config changes, like updating connection strings, if there is any appsettings values changes corresponding to production environments, etc.

Virtual Directory

An IIS Virtual Directory is essentially an alias to the physical directory. The IIS Virtual Directory is a directory name which may be accessed from the Internet to access the physical directory on the server.

The most common ways of creating virtual directory is done through two methods.

1.    Using IIS Manager

2.    Using Windows Explorer

Using IIS Manager

We can open IIS manager in 3 ways:

·         Type Inetmgr in RUN

·         Open Control Panel > Administrative tools > Internet Information Services

·         Right click My Computer, click Manage and expand Internet Information Services

Creation

Doing any of the above approach will bring us the IIS manager.

1.    Expand the local computer node, right click the Website under which you want to deploy the application and click New > Virtual Directory. It will bring a dialog like Figure 1.

Figure 1 - Create Virtual Directory

                                                     

 Click Next.

2.    It will bring the next window for entering “Alias” for our websites. See Figure 2.

Figure 2 - Virtual Directory Alias

 

Type the alias name you would like to assign for the applications virtual directory. I have used “test” for this article. Click Next.

3.    It will bring a window for linking our website's physical directory with virtual directory.

Figure 3 - Physical Directory Path

Browse to the location and select the website folder. Click Next.

4.    This will bring the window for specifying access permissions for the users. Select appropriate permissions.

Figure 4 - Virtual Directory Access Permission

  

I have not changed the default setting in this window as this permission is more than enough to run most of the applications. Click Next.      

5.    Click Finish. Thus we have created the virtual directory. 

Using Windows Explorer               

1.    Browse to the folder location where you copied the application and right click the folder and click “Sharing and security.”

2.    Open “Web Sharing” tab and select “Share this folder” which will ask for the Alias. Type an Alias name, click OK and click OK again. We have created virtual directory through windows explorer.

Configure ASP.NET version

Sometimes the server we are deploying may have both 1.1 and 2.0 framework installed. So we need to configure the applications to use appropriate framework. It can be done through the ASP.NET tab of virtual directory property box like in Figure 5.

Figure 5 - ASP.NET version picker

If it is 2.0 Application, select 2.0.xxxxx version or else 1.1.xxxx.

Application Pools

Application Pools or App Pools are introduced with IIS 6.0 to isolate websites into a group called Application Pools. Also we can say application pools are a group of one or more URL's that are served by a worker process, meaning applications running in a single app pools run in the same worker process w3wp.exe, thus providing a boundary so that if one application fails it does not hinder other applications running on other app pools. So as a good practice a highly confidential, secured website can be assigned with a separate app pool. Also we can use app pools to troubleshoot applications by isolating them to a separate application pool if we suspect that it creates problem. By using an application pool, we can have specific configuration settings to a worker process that services a group of applications or single application that is running under the App Pool. For example, you can configure worker process recycling and several other configuration options to match the needs of each application. We will see this in detail in coming sections.

With this introduction to Application pools we will move to our subject matter, creating Application pools in IIS 6.0.

Creation

A new application pool can be created using IIS Manager.

Steps

1.    Open IIS Manager.

2.    Expand local computer node. Right click Application Pools node and click New> Application Pool like Figure 6.

Figure 6 - Creating New Application Pool

                   

 It will open a dialog to create new app pool.

Figure 7 - Application Pool ID                          

 

Type a Pool ID for the app pool, the best practice to give identity is choosing a name relevant to the applications hosted. For example, if the app pool hosts a Shopping cart site, let the pool identity be ShoppingCartPool so that it can be easily identified as opposed to AppPool #1, 2, etc. Under Application pool settings> select “Use default settings for new application pool,” Selecting “Use existing application pool as template” will prompt as to select an existing app pool as the template so that same setting is applied for the newly created app pool.

3.    Click OK. A new application pool is created with default configurations.

Customizing Application pools

By default, Application pools are configured to use Network Service Account to service the request. At times we will end in a situation where we should use a separate account for servicing the request for different reasons. There are other configuration settings which some times need to be optimized, which are really done in exceptional situations. The coming sections will answer these things and take us through accomplishing this.

Steps

1.    Right click the Application pool you have created (Test Pool) in this example and click Properties. It will bring up a dialog like the one below.

Figure 8 - Application Pool Property recycling tab

                                          

Recycling tab is opened with default settings. Periodic recycling of your application pools is recommended to help to clean up memory fragmentation, memory leaks, abandoned threads and other disorders. Keep in mind that when an application pool recycles, session state information stored in-process is lost for that pool, but other pools are not affected. ASP.NET, however, does allow you to store your session state outside the worker process, so that session information is not lost during a recycle. We can recycle the worker process based on the number of requests and memory usages.

2.    Moving to Performance tab. Refer to Figure 9.

Figure 9 - Application Pool Property Performance tab

              

When the application does not receive a request for certain amount of time, it is said to be idle so this setting allow us to free up the occupied resource from the server after the specified time given here. Consider changing the Request queue limit if your application receives thousands request per second to mitigate Server busy messages. Most of the time Enable CPU monitoring is not used. Web garden setting should not be changed from 1, this specifies the number of worker process required to process the request for an app pool.

3.    Next, tab "Health" tab for configuring the health, i.e. the availability of the application can be configured. Refer to Figure 10.

Figure 10 - Application Pool Property Health tab

 

    

Enable pinging causes IIS to automatically query a worker process to see if it is responsive and utilizing network bandwidth. Enable rapid-fail protection helps to disable the app pool for specified number of failures occurred in the worker process. Startup time limit and shutdown time limit are self explanatory and failing to satisfy those condition falls under failure for rapid fail protection.

4.    The "Identity" tab is where we can configure the worker process identity.

Figure 11 - Application Pool Property Identity tab

 

The predefined setting’s default is to use network service account which is a less privileged account for security purposes. The other account that can be preconfigured is Local Service and LocalSystem account. Before making the App pool to use custom account known as Service accounts, we will explore what and why it is used.

Service Accounts

It is the identity of the App pool under which it services the request. It is the account that has very less privileges on the machine so as to reduce the security risk and loop holes. There can be several reasons to opt for custom service account over the Network service account. Some of the reasons are:

·         We can have different access controls for different applications on the local and network resources such as fileservers, etc.

·         It is also a mode of isolating one application from another by giving a separate identity so other applications cannot access the resource of another application.

·         We can prevent any accidental or deliberate changes to the access controls or permissions associated with the general purpose Network Service account from affecting your application.

See reference section for creating new service accounts.

One think to note here is if our site uses a database then make sure that the custom service account has the required access to the database.

Configuring Custom service account with Application Pool

In the above Figure select Configurable> type the service account id, password and enter. It will ask for password confirmation like the figure below. Click OK.

Figure 12 - Configure service account

After doing this restart the App pool by stopping and starting it again.

Associating Site with Application Pool

We need to associate our site with the App pool we created. It can be done by right clicking the site's virtual directory (Test in our case) and property. Select the TestPool from Application pool drop down in "Home Directory" tab as in Figure 13. Click Apply and OK.

Figure 13 - Associating site with Application Pool

 

We are at the end of the process and we need to do a smoke test for the application verification.

Possible Errors

Error

Service unavailable

Resolution

This is one of the ever green errors we often used to get mostly because of service accounts. The common problem will be this account might not be a member of IIS_WPG group on the server or check IIS_WPG group have Read & Execute, List Folder Contents, and Read permissions to the Web site directories. So precheck with a network admin who is creating the service account for you whether the account has all the required permissions on the server.

Error

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (Provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

Resolution

Again, there may be several reasons, the most common is checking if the service account has access to the SQL Server. This error occurs even if you are not using SQL Server 2005, i.e. the same error occurs even if you use SQL Server 2000. Similar error occurs if there is any problem in the connection string too.

Error

It is not possible to run different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process.

Resolution

When we host multiple versions of ASP.net in a single server, we may get this error in event log. The problem might be an application pool will be associated with 2 different applications that use different frameworks. So isolating this application into a different App Pools will solve the problem.

Points to note

This section highlights some of the important things to consider when we are deploying the application.

1.    Make sure the Web.Config setting is perfect, such as connection strings, App setting values, check <compilation debug="false"/> because setting it to true causes the application to be processed slow, memory consumption is more, scripts and images downloaded from the WebResources.axd handler are not cached.

2.    To trouble shoot the error if it occurred use <CustomErrors> section in Web.Config and make sure you are reverting back to the original settings.

3.    If we are running multiple versions of ASP.net on the same webserver do not use aspnet_regiis utility with –i switch to register the ASP.net with the IIS, instead use –s switch and register it for the particular site because using –i switch is going to update the entire IIS with the current version of ASP.net you are registering leaving the existing application configuration affected. For example, Aspnet_regiis –s W3SVC/1/ROOT/Test.

4.    By default, IIS does not allow dynamic contents like ASP\ASP.NET to be processed by IIS. So to allow this, Open IIS manager, click Web Service Extensions and Allow the Web Service Extensions if it is disabled as shown in Figure 14. If there is no extensions for processing ASP.net 2.0 application, we can add a new web service extension by clicking "Add a new Web service extension" link. Read more on MSDN on how to add web service extensions in IIS 6.0.

Figure 14 - Web service Extensions

References

Conclusion

As a web developer we should have the rudimentary knowledge of deploying the web application in the production and so this article will fulfill this anticipation. Checkout Microsoft’s KB articles for more support on Errors and resolutions. Happy Coding!!!



User Comments

Title: images are not visible   
Name: aamir
Date: 2013-01-20 11:39:43 PM
Comment:
this post explains the deployment in detail. i wonder if the images would be visible then it would have been a great.

thanks for the post
Title: Nice for beginers   
Name: developer from Pune
Date: 2010-12-11 5:28:20 AM
Comment:
Nice for beginers
Title: Nice   
Name: johnny
Date: 2010-09-24 4:29:44 AM
Comment:
Really nice one great stuff ... thanks alot
Title: Artical is good, but still error   
Name: manish
Date: 2010-08-17 12:34:21 AM
Comment:
I have an error

Failed to access IIS metabase.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.

The process account used to run ASP.NET must have read access to the IIS metabase (e.g. IIS://servername/W3SVC). For information on modifying metabase permissions, please see http://support.microsoft.com/?kbid=267904.


what I do
Title: Thankx   
Name: Neerav Chauhan
Date: 2010-05-01 7:23:04 PM
Comment:
Hello This article is really helpful.
Thank you very much
Title: Feedback   
Name: Chethan
Date: 2010-02-22 7:46:34 AM
Comment:
Great tutorial for begineer.
Thanks a lot....
Title: Good for Everyone   
Name: Jiaur
Date: 2009-11-14 10:44:59 PM
Comment:
Not Only great but also excellent article. Thanks & go ahead.
Title: Well done!   
Name: Alan Ramos
Date: 2009-08-25 8:05:33 AM
Comment:
This is really great. I have just read through the article and this steps are really great. I am glad that I found the link.
Title: Thanks   
Name: Nuwan
Date: 2009-07-18 12:32:23 AM
Comment:
Thank you very much Satheesh. This is really a great article
Title: Thanks   
Name: Prathi
Date: 2009-07-08 6:50:54 AM
Comment:
ITs very good. Thanks very much man..
Title: Deploying ASP.NET Applications   
Name: Ezeamama Andrew
Date: 2009-05-13 7:04:56 AM
Comment:
Great information for ASP.NET developers
Title: IIS 7   
Name: Md. Ismail
Date: 2009-03-17 1:05:10 AM
Comment:
Great One!!!
Looking forward to similar article on IIS 7
Title: Deploying ASP.NET Applications   
Name: vikash
Date: 2009-03-06 1:30:53 AM
Comment:
this is good for all developers
Title: Deploying ASP.NET application   
Name: Sunil Dhas
Date: 2009-02-24 1:59:42 AM
Comment:
Really a helpfull reading....
Title: Deploying ASP.NET application   
Name: Hiren Nagar
Date: 2008-10-02 4:28:02 PM
Comment:
It's a great article. Thanks for posting this information.
Title: Adding additional comments.   
Name: Prabhurajan
Date: 2008-04-15 2:29:47 AM
Comment:
Hi Satheesh Babu,
Really the Article was very good, to add your points, i have some suggestion during deployment.
There are some places, were Firewall is Mandatory and it cannot be disabled. In such condition, after giving appropriate Permission. Next step is to enable the Web Server(Http) in LAN Settings of the Firewall.

Goto Start --> Run --> type 'Firewall.cpl'.
Goto Advanced tab, in Local Area Network setting -> Click Settings.
After clicking Settings, you will get the list of services. Check WebServer(Http) is checked or not.
After checking WebServer only, your WebSite can be accessed from Other Machines.

Thanks and Regards,
Prabhu
Title: RE:virtual directory permission   
Name: Satheesh babu
Date: 2007-11-19 11:52:15 AM
Comment:
Hi kiran,
ya definitely the service account needs the required permissions to write...
Title: virtual directory permission   
Name: kiran
Date: 2007-11-19 2:47:11 AM
Comment:
hi Satheesh ,
i am facing some problems in deploying my app . i m editing my resourse files(.txt) on server and i users can upload files to server this will follow creating directory on server . do this will need that virtual directory will need write Permission../add any user account to virtual directory?
btw thanx for sharing valuable information.
Title: Deploying ASP.NET Applications   
Name: Kiran P
Date: 2007-11-18 11:42:46 AM
Comment:
Thanks for the valuable info
Title: Deploying ASP.Net Applications   
Name: Rekha
Date: 2007-11-12 10:57:38 AM
Comment:
It is a gud article....worth reading..............

Thanks
Title: RE:IIS 6.0 problems   
Name: Satheesh babu
Date: 2007-10-26 2:16:53 PM
Comment:
Hi guys,
Thank you so much for the valuable feedbacks!!!
Pramod:
I think you havn't installed IIS 6.0.IIS 6.0 is default websrver of windows 2003 and it will come with Windows 2003.I guess you are trying to do something in your desktop PC(like 2000 or XP). App pool concept is there only in IIS 6.0.

For your info:
Windows 2000 ---> IIS 5.0
Windows XP ---> IIS 5.1
Windows 2003 ---> IIS 6.0
Title: IIS 6.0 problems..?   
Name: Pramod Aryan
Date: 2007-10-25 3:04:26 PM
Comment:
Hi sateesh ur arcticle is v ery much handy for rookie developers like me.But i am facing a problem with IIS 6.0.i have downloaded and installed it but i cant see application pooling in that console root can u please help me in this regard.
Title: Deploying ASP.NET Applications   
Name: Vivekananda
Date: 2007-10-23 9:07:37 AM
Comment:
Xplains each and every aspect of web site deployment & its very useful to fine tune the existing applications thro' IIS too.....Useful one!!!
Title: Deploying ASP.NET Applications   
Name: Jai
Date: 2007-10-22 11:59:48 PM
Comment:
Even though we know something about this already, it goes little bit deeper in all aspects.

Good , worth reading.
Title: ASP.NET Applications Deployment   
Name: Nitin Sharma (Dot Net Developer)
Date: 2007-10-19 1:02:41 AM
Comment:
It's really Fundoo yar..!!!! V V Informative..
Grat going ASPALLIANCE.COM

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-05-24 7:10:25 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search