Last time I wrote a little app performance improvement in general, but right now I want to focus on apps developed in ASP .NET. I’ll try to be really concise and clear.
The specific case of ASP .NET
First, a little bit about ASP .NET. It is an open-source server-side web application framework designed for web development. ASP .NET was developed by Microsoft with the goal of providing programmers a tool to build dynamic web sites, web applications and web services. I’ve worked a lot with ASP .NET, and these are the tips I have for you:
Disable the Session State
There’s no point on enabling ASP session state if you are not going to use it. Remember you can disable this option for specific pages instead of doing it for all of them.
<% @ Page language = “c #” Codebehind = “WebForm1AutoEventWireup = “false” Inherits = “WebApplicat
EnableSessionState = “false” %>
You can also disable the Session State through the web.config. To do this, you have to turn Off the value of the <sessionState> mode.
Avoid server-side validation
Use the client-side validation instead. The server-side validation consumes valuable resources in the servers and using it can overrun your server-side code or generate a very slow response from the server.
Don’t use controls that are heavy in HTML
ASP .NET is a great platform. Unfortunately, some controls like DataList, DataGrid and DataView are heavy in HTML. Application performance could be affected by that! Which control can I use? The ASP .NET repeater control is awesome.
Use HttpResponse.IsClientConnected before performing a large operation
/ / If still connected, redirect
// to another page.
Response.Redirect (“Page2CS.aspx”, false);
Apply HttpServerUtility.Transfer instead of Response.Redirect
It is very common to use Response.Redirect, but this should only be used when transferring data to another physical web server. Therefore, if you are performing tranfers on your own server, HttpServerUtility is here to save you from useless HTTP requests.
Check Page.IsValid when using Validator Controls
Make sure to verify Page.Is.Valid before processing your forms. ASP. NET does not necessarily do everything for you when dropping validator controls.
Exceptions are probably the main issues in web apps deceleration and the creation of heavy resources. Write your code to avoid this problem, don’t code by exception!
This is something I recommend to use when you have large strings, when you are concatenating more than 3 times. It is way faster than String + String!
Turn off ViewState
Doing this will make your app faster because, when not using form, postback controls tend to turn on ViewState. This could be the cause of your app being slow and not performing well.
this.Init += new EventHandler(Page_Init);
private void Page_Init(object sender, System.EventArgs e)
this.EnableViewState = false;
Use the Finally Method
If you have opened any connection to the database or files, make sure to close them at the end. The best block to do this is the finally block because is the only block that will close everything out.
public static void AddSomething (string something)
using (SqlConnection connection = new SqlConnection(“…”))
So there you go, are you in the process of developing a web app? Follow the tips in my last post and in this one combined, and you will have excellent results. These are just some personal tips I like to apply! Let’s not forget that the main thing to do while developing an app is to identify where bottlenecks typically occur, their causes, and what to do to prevent them from occurring.