Increasing Performance of ASP.Net web application

While developing large application performance is the major factor. Performance plays crucial role in development of any application. There are many ways to increase the performance of the application.Some of them are discussed below.

  1.  Page Level and Server controls:
  2.  State Management Level:
  3.  Data Access Level: 
  4.   Web Application Level:
  • Page Level and Server controls:
    • Avoid unnecessary round trips to the server.
      • use Microsoft Ajax and partial-page rendering to accomplish tasks in browser code.
    • use IsPostBack Property of page object to avoid unnecessary processing.
      • Avoid executing code on each postback if it only has to run the first time the page is requested.
    • while developing custom server controls. design them to render client script for some of their functionality.
      • Creating Custom Client Script by Using the Microsoft Ajax Library.
    • Use Server.Transfer and cross-page posting to redirect between ASP.NET pages in the same application.(For accessing controls and their values from the source page).
    • Leave buffering on unless you have a specific reason to turn it off .
      • There is a significant performance cost for disabling buffering of ASP.NET Web pages.
  •  State Management:
    •   Use View state of control when it is required.
      • By default, view state is enabled for all server controls. Disable it , by setting  EnableViewState property to false, as in the following example:
        <asp:datagrid enableViewState=”false” datasource=”…” runat=”server”/>
    • Avoid using view state encryption unless you have to.
      • View state encryption prevents users from reading view-state values in the hidden view-state form field.
    • Select appropriate session-state provider for your application. 
      • Asp.Net provides various ways to store data in a session.Based on the requirement and conditions of the application select appropriate session storage. Example:in-process session state, out-of-process session and creating custom session also possible.
    • Disable session state when you are not using it.
      • To disable session state for a page, set the EnableSessionState attribute in the @ Page directive to false, as in the following example:
        <%@ Page EnableSessionState="false" %>
        To disable it at application level,Use this property in web.config.
         <sessionState mode="Off" />
  •  Data Access Level:
    • Use SQL Server and stored procedures for data access:
      • SQL Server is the recommended choice for data storage to create high-performance, scalable Web applications.
    • Use the SqlDataReader class for a fast forward-only data cursor:
      • The SqlDataReader class creates a forward-only, read-only data stream that is retrieved from a SQL Server database.
    • Cache data and page output whenever possible:
      • use caching if there is no dynamic content request for every page request.
    • Use SQL cache dependency appropriately.
      • Use Table-based polling feature provided by SQL Server. In table-based polling, if any data in a table changes, all cache items that are dependent on the table are invalidated
    • Use data source paging and sorting instead of UI:
      • Don`t pull all the data from the database. use paging concepts and retrieve the number of records that are necessary to display.
    • Balance the security benefit of event validation with its performance cost.
    • Use SqlDataSource control caching, sorting, and filtering .
      • Set the number of threads per worker process.
          • Recycle processes periodically.
              • Preload the application.
                • initial start up response time can be improved by preloading.
              • Precompile Web site projects.
                • Initially project is batch compiled upon first request and this batch compilation compiles all pages in a directory to improve memory and disk usage.So  Precompile the whole project before deploying it into the server.
              • Disable debug mode. 
                • Disable debug mode before you deploy a production application.
              • Tune the configuration files for the Web server computer and for specific applications. Web Application Level:
    • For applications that rely extensively on external resources, enable Web gardening on multiprocessor computers.

Happy programming, share if you find usefull.

Source