20 tips to improve Asp.net Application Performance

Source: Internet
Author: User

there are certain things you shoshould 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.

  1. 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 allows ss the application in the web. config by setting the mode Value to off.

  2. Output buffering
    Take 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%>
  3. 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.
  4. Repeater control good, datalist, DataGrid, and dataview controls bad
    Asp.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!
  5. Take advantageHttpresponse. isclientconnectedBefore algorithm Ming 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...

  6. Use httpserverutility. Transfer instead of response. Redirect
    Redirect's are also very chatty. They shocould 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.
  7. Always check page. isvalid when using validator controls
    So 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 stored is the isvalid flag is set to false. So make sure you check page. isvalid before processing your forms!
  8. deploy with release build
    make 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.
  9. 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"  pageoutput = 
            "false" /> 
           
             "false"  requestlimit = 
             "10"  pageoutput = 
             "false"  tracemode = 
             "sortbytime"  localonly = 
             "True" /> 
            
              "false" /> 
            
           
          
          
         
  10. Page. ispostback is your friend
    Make sure you don't execute code needlessly. I don't know how many web developers forget about checking ispostback! It seems like such a basic thing to me! Needless processing!
  11. Avoid exceptions
    Avoid throwing exceptions, and handling useless exceptions. exceptions are probably one of the heaviest resource hogs and causes of slowdowns you will ever see in Web applications, as well as Windows applications. write your code so they don't happen! Don't code by exception!
  12. Caching is possibly the number one tip!
    Use Quick page caching and the Asp.net cache Api! Lots to learn, its not as simple as you might think. There is a lot of strategy involved here. When do you cache? What do you cache?
  13. Create per-request Cache
    Use httpcontect. items to add single page load to create a per-request cache.
  14. Stringbuilder
    Stringbuilder. append is faster than string + String. However in order to use stringbuilder, you must
    NewStringbuilder ()

    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

  15. turn off viewstate
    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 ;}
  16. Use Paging
    Take advantage of paging's simplicity in. net. only show Small subsets of data at a time, allowing the page to load faster. just be careful when you mix in caching. how many times do you hit the page 2, or page 3 button? Hardly ever right! So don't cache all the data in the grid! Think of it this way: How big wowould the first search result page be for "Music" on Google if They cached all the pages from 1 to goggle
  17. Use the appoffline.htm when updating Binaries
    I hate the generic Asp.net error messages! If I never had to see them again I wocould be so happy. Make sure your users never see them! Use the appoffline.htm file!
  18. Use controlState and not viewstate for controls
    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.
  19. Use the finally Method
    If you have opened any connections to the database, or files, etc, make sure that you close them at the end! The finally block is really the best place to do so, as it is the only block of code that will surely execute.
  20. Option strict and option explicit
    This is an Oldy, and not so much a strictly Asp.net tip, but. net tip in general. make sure you turn both on. you shoshould never trust. net or any compiler to perform conversions for you. that's just shady programming, and low quality code anyway. if you have never turned both on, go turn them on right now and try and compile. fix all your errors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.