Performance

Performance is often an important issue in computer applications, especially in web applications receiving a large number of requests. One obvious way to improve performance is to buy faster hardware with more memory. But you can also tune your code to enhance performance in many ways, some of them significant. We’ll begin by examining some of the areas specific to ASP.NET that offer the greatest performance improvements and then examine some of the general .NET topics related to improving performance.

Tip

Several Microsofties involved with writing the .NET Framework used the word performant to mean that something is delivering higher performance. We can’t find it in any dictionary, but it seems like a good word.

ASP.NET-Specific Issues

Correctly using the following features of ASP.NET offers the greatest performance improvements when an ASP.NET application is running.

Session state

Session state is a wonderful thing, but not all applications or pages require it. For any that do not, disable it. You can disable session state for a page by setting the EnableSessionState attribute in the Page directive to false, as in this example:

    <%@ Page Language="C#" EnableSessionState="false"%>

If a page will not be creating or modifying session variables but still needs to access them, set the session state to read-only:

    <%@ Page Language="C#" EnableSessionState="ReadOnly"%>

By default, web services do not have session state enabled. They only have access to session state if the EnableSession ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.