Twenty ways to increase the performance of asp.net applications of is simple and effective

  • 2020-05-07 19:31:16
  • OfStack

1. Disable session
Be sure to disable session session tracing if you do not use it. You can set the following in each asp.net page:
< %@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1"

EnableSessionState="false" % >

Of course you can design it in the web.config application configuration Settings < sessionState > The value of mode is Off.

2. The output buffer is set to
This method is very helpful for your application.
The asp.net application basically generates data in bulk on the server side, so you must set Response.Flush to clear the buffer. This will reduce the buffer pressure on the server side.

< %response.buffer=true% >
replace
< %response.flush=true% >

 

3. Avoid server-side validation.
Replace server-side validation with client-side validation. Server-side data validation will consume your server

On the resource, and will be replaced by a large number of page data back.

 

4. Use Repater controls more than DataList, DataGrid, and DataView controls

Asp.net is a very good platform, unfortunately, there are a lot of controls that generate a lot of html code, this

The Asp.net repeater control is very useful. Use it and you will

Write some extra code, but in the future you'll find that the benefits outweigh the hassle.

 

5. Please use HttpResponse.IsClientConnected for large action operations
if (Response.IsClientConnected)
              {
                      // If still connected, redirect
                      // to another page.
                      Response.Redirect("Page2CS.aspx", false);
              }
Is there anything wrong with Response.Redirect

 

6. Replace Response.Redirect. with HTTPServerUtility.Transfer
Redirect(redirection) is cumbersome and is only used to jump from the current physical server to another service

If you only use transfer(forward) for page hopping within this server, it will be much less

There are required client requests.

 

7. When using server-side validation, be sure to use Page.IsValid to check that the page can validate
Because you used the validation control, you might think that asp.net would handle all of the following, right?

Wrong! The IsVlid property is changed to fasle when invalid data is sent to the server. Please check the Page.IsValid property before proceeding with your form

 

8. To deploy the application, use Release version
When deploying an application, make sure that your application is an Release version and not an Debug version.

Request timeouts are extremely likely if you use the debug template. Deploy the Release version and you will see a significant speed increase.

 

9. Turn off Tracing(tracking)
Tracing is very scary, have you forgotten to close it? If not, be sure to edit web.config and close it. It will take up a lot of your program's resources
< configuration >
  < system.web >
  < trace enabled="false" pageOutput="false" / >
  < trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/ >
  < compilation debug="false" / >
  < /system.web >
  < /configuration >

 

10.Page.IsPostBack always use
Make sure you don't execute too much return code. I've lost count of how many developers forget to check the IsPostBack property.

 

11. Avoid the exception
Avoid throwing and handling exceptions. Exception handling is used only as a last resort.

Exceptions are a significant waste of server-side resources and can significantly reduce efficiency. Avoid exception handling.

 

12. Set cache (Caching)
Use the page to quickly set the page Caching and use the ASP.net buffer API!

There's a lot to learn, and this isn't as easy as you might think. Do you use the cache?

 

13. Set the cache per request
Using HTTPContect.Items only adds one page to set the cache for each request.

 

14. is used for the StringBuilder class
StringBuilder.Append is much faster than String + String.

If the string you are concatenating to is relatively unusable, the StringBuilder.Append method is recommended for more than 3 concatenations, as well as String.Concat

 

15. Close ViewState
If you do not return the form data, close viewsate. Control will automatically open viewstate and slow down your application.

public ShowOrdersTablePage()
{
      this.Init += new EventHandler(Page_Init);
}

private void Page_Init(object sender, System.EventArgs e)
{
      this.EnableViewState = false;
}

 

16. Use paging
.net application pagination takes advantage of application efficiency. Showing as little data as possible at a time will speed up the page. Be careful with mixed caches and do not set all data in the cache.

17. Use AppOffline.htm when updating an application
I hate asp.net default error messages. I'm so happy if I never see those error messages again. Make sure your users don't see it either. Use AppOffline.htm instead.

 

Control USES ControlState instead of ViewState

 

19. Recycle using the finally method
If you use database connections and access files heavily in your application, be sure to close them when you're done.

The finally block is the last to be executed in the program, so the code in here will be executed, and the closing code will be executed in this method block

20. Please implement strictly according to the above methods


Related articles: