Tips to Improve an ASP.Net Application

Microsoft has already revealed its plan to completely revamp ASP.NET. In addition to being a completely redesigned version of the web framework, ASP.NET Core 1.0 will be both open source and cross-platform. The updated version of ASP.NET will still be compatible with the web applications developed with its older versions. Also, ASP.NET Core 1.0 will run on both .NET 4.6 and .NET Core 1.0. Hence, the developers will still have option to run the existing ASP.NET applications without making major changes. But they must explore ways to boost the performance of the ASP.NET applications to keep the visitors engaged and deliver optimized user experience.

15 Tips to Boost the Performance of Your ASP.NET Application

1) Upgrade to the Latest Version of ASP.NET

Each new version of ASP.NET comes with a several new features to boost the performance and functionality of the web application. For instance, ASP.NET 4.5 came with improved Multi-core JIT compilation, a new garbage collector, and new features like app suspension. Likewise, ASP.NET Core 1.0 will come with several new features to boost the performance and compatibility of web applications. You can always take advantage of the new features and enhancements to boost the ASP.NET application’s performance, and handle large amount of data without making any changes to the code.

2) Compress the Files

The performance of an ASP.NET application is impacted adversely when request for static content is sent to the web browser frequently. You can always consider compressing the static content to reduce bandwidth and process requests faster. You also can further avail the features provided by ASP.NET to easily compress the static content. For instance, you can simply enable the urlCompression option to compress or gzip the content sent to the web browser and reduce bandwidth significantly.

3) Keep JavaScript and CSS Files Separate from View

It is a common practice among ASP.NET developers to store front-end resources like JavaScript and CSS files within the views. When the front-end files are stored within a view, the view is regenerated based on each user request. Also, the storing options prevent developers from reaping benefits of data and output caching options. You can easily improve the performance of the ASP.NET applications by storing these files outside the views and connect the files to views as links.

4) Avail Data Caching Option

Often repeated database query executions affect the ASP.NET application’s performance and scalability adversely. You can take advantage of output caching option to avoid repeating execution of database queries. Further, the mechanism will make the data available to user when data source is not available temporarily. You can take advantage of the classes provided by .NET Framework and defined in System.Runtime.Caching namespace to activate data caching without putting extra effort.

5) Avail Output Caching Option

Like repeated database query execution, the rendition of regularly used pages or views also affect the ASP.NET application’s performance negatively. You must use output caching to cache the regularly used pages or views that do not render dynamic content. ASP.NET further enables programmers to implement cache on MVC views simply by adding the [OutputCache] attribute to either each controller action or the entire controller class, developers can check here are the top controls for asp.net.

6) Avail Kernel Mode Cache

Like data and output cache, you can also use kernel mode cache option to enhance the performance of the ASP.NET application. Each request to the web server goes through a number of stages. Initially the request is received by http.sys which is designed as http listeners and sits directly on the operating system kernel. When you enable kernel mode cache, http.sys can listen to requests directly from TCP layer. Hence, a request can be processed quickly by ignoring the page lifecycle, database query execution and custom code.

7) Check and Remove Unused HTTP Modules

Each request made by the user has to go through ASP.NET pipeline. The ASP.NET pipeline contains several http modules, along with an http handler. The request is finally processed by the http handler after passing through all http modules. So the request processing time depends on the number of http modules included in ASP.NET pipeline. You can always identify and remove the unused modules from the pipeline to ensure that the request passes through only relevant and useful http modules.

8) Minimize Number of Database Connections

The performance of an ASP.NET application deteriorates when it tries to improve connection pooling by holding on to many database connection for longer duration. Each time the number of connection hold by the application exceeds the predefined limit, the ASP.NET application stop working properly. You can always take advantage of stored procedures to process frequently used queries efficiently without putting additional overhead on the database server. The stored procedure will further help you to optimize data access performance of the web application significantly.

9) Don’t use ViewState to Boost the Page Load Time

You can easily boost page load time by enabling ViewState. But you must not forget that each byte added to the web page by enabling its ViewState puts extra bytes on the network traffic. So you must explore ways to optimize page load without enabling ViewState. You can even consider removing the runat=”server” attribute from the web page to avoid adding extra bytes to the network traffic. However, you must check and optimize the loading speed of each web page to boost the application’s user experience and search engine ranking.

10) Minify and Bundle Front-End Resources

You can easily boost the performance of the ASP.NET application by minifying and bundling the JavaScript and CSS files. The number of HTTP requests will decrease significantly when you bundle the JavaScript and CSS files into a single large file. Likewise, minified JavaScript and CSS files will reduce the size of data transferred between the web server and client. You can easily bundle and minify the custom JavaScript and CSS files by using a number of open source tools.

11) Control Image Requests

You can boost the performance of an ASP.NET application significantly by controlling image requests. With most websites nowadays using high resolutions images and graphics, image request control becomes pivotal. You can control the image requests through two distinct options — image sprite and Base64 data URIs. Image sprite enables you to combine multiple single images into a single image file. You can use CSS to reposition these images within the web page based on the large image file. Likewise, you can use base64 data URIs to obtain and render images quickly without making individual requests to the server.

12) Use Content Delivery Network Servers

The content delivery network (CDN) servers are designed specifically to deliver static content in a faster and more efficient way than application web server. You need to ensure that the third-party JavaScript code generated though various frameworks and tools must use CDN server instead of web application server. The CDN server will deliver the front-end resources to the web browser more quickly. At the same time, it will boost the web application’s speed by availing the JavaScript cached by various web browsers.

13) Deploy the Site in Release Build Mode

While deploying the ASP.NET application in production, often programmers opt for Debug Build instead of Release Build. When the website runs in debug mode in productions, additional PDBs will be created and chances of request timeout will increase. Before deploying the application, you must switch from the Debug Build mode to Release Build mode to increase the speed of the application without putting extra effort.

14) Remove All Empty Methods from global.asax

You have option to include a number of application level methods in global.asax. Some of these application level methods are executed once on the first request, while others are executed frequently on each request. The ASP.NET application further looks for the application level methods included in the global.asax on each request. It even executes the empty methods included in global.asax despite having no code inside. Hence, you must review the methods present in the global.asax, and remove all empty methods to boost the application’s speed. It is also a good idea to remove most methods from global.asax and try to incorporate them into page cycle.

15) Validate User Input through Client-Side Scripts

You can always reduce pressure on the server and boost the web application’s speed by validating user input through JavaScript. The JavaScript code will help you to validate all inputs comprehensively without making the application interact with the web server. You still have option to validate the user input through client-side controls. But there are chances that the user may disable JavaScript on the web browser while accessing the ASP.NET application. Hence, you need to validate the input submitted by the user at the server side to keep the application secure.

There are chances that ASP.NET Core 1.0 may not be support all features provided by its predecessors. Hence, the developers have to make changes to the source code of the existing ASP.NET applications to improve their performance and take advantage of the new features included in ASP.NET Core 1.0. The one time modification will boost the application’s compatibility and performance in the longer run.