Microsoft & .NETFive Steps for Improving Web Application Performance

Five Steps for Improving Web Application Performance content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Are you getting close to your go live to production deadline on your ASP.NET web application, but having some performance issues? The goal of every developer should be to develop a web application with the understanding of proper memory management and how a web server handles requests. Even with this goal in mind, it is possible to miss ways of improving performance while developing your application. I am going to outline five steps for you to make some quick performance enhancements to your web application.

1. Properly Handling Data Access Objects

One way to really kill the memory on your server is by not handling data access objects correctly. When creating a data access object, it is important that you have the proper understanding of its life span and what it takes to dispose of it when it is no longer needed. I have often seen developers create, open, and consume a DataReader, but do nothing to dispose of it. Make sure that your data access objects are properly managed; this will save you a big headache from wondering why your IIS worker process keeps consuming memory until it crashes. Do a quick search within your solution for any instance of a new DataReader being created. For each instance found, verify that your DataReader has been closed and disposed. Use a try/catch/finally block around your DataReader or a using statement so that if an exception occurs, the finally block will handle closing and disposing your DataReader.

Example of using statement:

using (IDataReader reader = MySite.GetSearchResults())
   //Consume the datareader
   while (reader.Read())
      //Do something with the data

Example of try/catch/finally block:

IDataReader reader;
   reader = MyWeb.GetSearchResults();
   while (reader.Read())
      //Do something with the data
catch (Exception ex)
   //Log the exception
   //Dispose the object if it exists
   if (reader != null)

2. Managing IIS Application Pools

Typically, when dealing with a web application, there is more than one component to it. You usually have your main web site, one or more web services, and possibly an image handler application. IIS 6.0 gives you the opportunity to create multiple application pools. Application pools allow you to group your applications to be served by individual worker processes. One of the advantages of separating your applications into individual application pools is that each worker process uses its own set of memory. No matter how much memory you have on your server, typically an ASP.NET worker process will begin to slow to a crawl when the memory that it consumes gets over 800-900 megabytes. Separating your applications into individual application pools allows multiple worker processes to handle requests while keeping the memory lower per worker process. Refer to Microsoft documentation for more information on creating an application pool.

3. Managing ASP.NET State

Having an understanding of the different types of ASP.NET states is very important to improve application performance. ASP.NET has many different states, but the states that you should be particularly aware of is application state, session state, and profile properties because these all store data in memory on the server. Avoid storing too much data in any of those three states unless it is determined as necessary. If you do need to store data in session state, store only the data you need, such as identifier fields or static data that is frequently used. There are plenty of articles on the web that outline all of the different ASP.NET states if you would like to dig further into each of them. Each type of state should be used for its intended purpose only when needed. Take the time to learn and understand them thoroughly.

Another state that I want to bring to your attention is view state; this affects the client. It is used to preserve values on the page or control between round trips to the server. By default, view state is turned on for your ASP.NET pages and controls. Not all of your web pages are going to require view state. Web pages that are relatively large can have an enormous amount of data stored in view state. One way to see exactly what the view state looks like on a given page is to do a “View Source” from your web browser. Yeah, that big block of encrypted looking data at the top of the page is your view state. Take some time to evaluate each of your web pages to determine whether or not view state is needed. Pages that do not have any server postback events can have the view state turned off. You can turn view state off for an entire page, usercontrol, or on a control by control basis as needed. If you turn view state off for a page or control, make sure you thoroughly test your pages to verify that they continue to function correctly.

4. Cleaning Up Style Sheets and Script Files

A quick and easy way to improve your web application’s performance is by going back and cleaning up your CSS Style Sheets and Script Files of unnecessary code or old styles and functions. It is common for old styles and functions to still exist in your style sheets and script files during development cycles and when improvements are made to a website. Many websites use a single CSS Style Sheet or Script File for the entire website. Sometimes, just going through these files and cleaning them up can improve the performance of your site by reducing the page size. If you are referencing images in your style sheet that are no longer used on your website, it’s a waste of performance to leave them in there and have them loaded each time the style sheet is loaded. Run a web page analyzer against pages in your website so that you can see exactly what is being loaded and what takes the most time to load.

5. Load Testing with Visual Studio Team System

Load testing is essential to discovering performance problems and measure response times prior to going live to production. Visual Studio Team System (VSTS) includes an excellent and simple tool to load test your web application and provides handy reporting capabilities. Using the load test wizard makes it simple to create your load test project by guiding you through all of the necessary steps. Start by creating one or more web tests and configuring properties on each web test to simulate your users. VSTS comes with the Web Page Recorder; it allows you to record a series of steps that you perform on your website to create your web test. The web test is used by the simulated users as part of the load test. Set up performance counters on your server using the performance monitor. Use the performance counters to watch specific activity on your web server such as private bytes, virtual bytes, and CPU percentage. If you have memory leaks in your application, you will easily discover this by watching the memory. Your results will vary slightly depending on what your application loads, but the web server’s memory should reach a consistent amount and remain stable. The figure below is a sample of the VSTS load test in action.

Figure 1: The VSTS load test in action


The five steps that you covered for improving web performance are meant to provide quick results without very much development or work involved. However, if you decide to implement any of these steps into your web application, please do a careful analysis and research each area further so that you make the correct decisions for your application. The best performance you are going to get requires a sound structure and planning before development begins. Hopefully, you are able to find these tips useful and can gain some performance improvements out of them.

About the Author

Andrew Bonslater (MCAD, MCSD) is a solutions developer for mid to large-sized organizations. He is a thought leader with Crowe Chizek in Indianapolis, Indiana. Andrew specializes in Web-Based solutions. You can reach him at

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories