Not a .net Developer?
Are you an asp.net developer? Want to get read a Focus T25 Review? If you aren’t don’t worry, we have similar posts in the works for Ruby, PHP, and other developers out there. If you are an ASP.net developer, listen up!
Get Ready for Massive Gains
There are certain things you should take into account when you are developing your applications. Over the last 12 years or so of working with asp and asp.net, I have learned to avoid and do certain things that increase your application performance by a massive amount! Below are my top 20 tips to improving ASP.net application Performance.
- Disable Session State
Disable Session State if you’re not going to use it. By default it’s on. You can actually turn this off for specific pages, instead of for every page:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" EnableSessionState="false" %>
You can also disable it across the application in the web.config by setting themode value to Off. - Output BufferingTake advantage of this great feature. Basically batch all of your work on the server, and then run a Response.Flush method to output the data. This avoids chatty back and forth with the server.
<%response.buffer=true%>
Then use:<%response.flush=
true%> - Avoid Server-Side Validation
Try to avoid server-side validation, use client-side instead. Server-Side will just consume valuable resources on your servers, and cause more chat back and forth. - Repeater Control Good, DataList, DataGrid, and DataView controls BadAsp.net is a great platform, unfortunately a lot of the controls that were developed are heavy in html, and create not the greatest scaleable html from a performance standpoint. ASP.net repeater control is awesome! Use it! You might write more code, but you will thank me in the long run!
- Take advantage of HttpResponse.IsClientConnected before performing a large operation:
if (Response.IsClientConnected) { // If still connected, redirect // to another page. Response.Redirect("Page2CS.aspx", false); }
What is wrong with Response.Redirect? Read on… - Use HTTPServerUtility.Transfer instead of Response.RedirectRedirect’s are also very chatty. They should only be used when you are transferring people to another physical web server. For any transfers within your server, use .transfer! You will save a lot of needless HTTP requests.
- Always check Page.IsValid when using Validator ControlsSo you’ve dropped on some validator controls, and you think your good to go because ASP.net does everything for you! Right? Wrong! All that happens if bad data is received is the IsValid flag is set to false. So make sure you check Page.IsValid before processing your forms!
- Deploy with Release BuildMake sure you use Release Build mode and not Debug Build when you deploy your site to production. If you think this doesn’t matter, think again. By running in debug mode, you are creating PDB’s and cranking up the timeout. Deploy Release mode and you will see the speed improvements.
- Turn off Tracing
Tracing is awesome, however have you remembered to turn it off? If not, make sure you edit your web.config and turn it off! It will add a lot of overhead to your application that is not needed in a production environment."false"
StringBuilder.Append is faster than String + String. However in order to use StringBuilder, you must
new StringBuilder()
Therefore it is not something you want to use if you don’t have large strings. If you are concatenating less than 3 times, then stick with String + String. You can also try String.Concat
If you are not using form postback, turn off viewsate, by default, controls will turn on viewsate and slow your site.
public ShowOrdersTablePage() { this.Init += new EventHandler(Page_Init); } private void Page_Init(object sender, System.EventArgs e) { this.EnableViewState = false; }
If you followed the last tip, you are probably freaking out at the though of your controls not working. Simply use Control State. Microsoft has an excellent example of using ControlState here, as I will not be able to get into all the detail in this short article.
There are hundreds more where these came from, however I really feel that these are the most critical of the speed improvements you can make in ASP.net that will have a dramatic impact on the user experience of your application. As always if you have any suggestions or tips to add, please let us know! We would love to hear them!
Have web development!
0 comments:
Post a Comment