20 ways to increase the performance of asp.net applications (simple and effective)

Source: Internet
Author: User

1. Disable session
If you cannot use session tracing, disable 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 the <sessionState> mode Value to Off in the web. config application configuration settings.

2. output buffer settings
This method is very helpful to your application.
The asp.net application basically generates data in batches on the server. At this time, you must set Response. Flush to clear the buffer. This reduces the buffer pressure on the server.

<% Response. buffer = true %>
Replace
<% Response. flush = true %>

 

3. Avoid server verification.
Use client-side verification instead of server-side verification. server-side data verification will consume a lot of your server

And a large amount of page data will be returned.

 

4. Use the Repater control whenever possible, instead of the DataList, DataGrid, and DataView controls.

Asp.net is a very good platform. Unfortunately, there are many controls that generate a large number of html code.

The sample must cause performance problems. The .Asp.net repeater control is very useful. You will

Write more code, but in the future you will find that it brings far more benefits than writing more code.

 

5. Use HttpResponse. IsClientConnected
If (Response. IsClientConnected)
{
// If still connected, redirect
// To another page.
Response. Redirect ("Page2CS. aspx", false );
}
Is there any error in Response. Redirect? Continue with the answer below.

 

6. Use HTTPServerUtility. Transfer to replace Response. Redirect.
Redirect (redirection) is very troublesome. It is only used to jump from the current physical server to another service.

If the server only jumps to the page, use transfer (forwarding). This will reduce the number

Necessary client requests.

 

7. Use Page. IsValid to check whether the Page is verified.
Because you have used the verification control, you may think that asp.net will handle the following things, right?

Error! When invalid data is transmitted to the server, the IsVlid attribute is changed to fasle. Check the Page. IsValid Attribute before processing your form.

 

8. Use the Release version to deploy the application.
When deploying an application, make sure that your application is in the Release version instead of the Debug version. If you think this is irrelevant, you will be wrong.

If the debug template is used, request timeout is very likely. Deploy it to the Release version, and you will find that the speed is greatly improved.

 

9. Disable Tracing)
Tracing is terrible. Have you forgotten to close it? If it is useless, Please edit web. config and close it. It will occupy a lot of your program 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 should be used frequently
Please be sure not to execute too much back-to-code. I do not know how many developers forget to check the IsPostBack attribute. I often use this attribute check in normal development.

 

11. Avoid exceptions
Avoid throwing and processing exceptions. Unless you have to handle exceptions.

Exceptions are a waste of server resources and greatly reduce efficiency. Try not to use exception handling.

 

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

There are many things to learn. This is not as simple as you think. There are many strategies to adopt. When should I use buffering? Are you using the cache?

 

13. Set the cache for each request
To use HTTPContect. Items, you only need to add one page to set the cache for each request.

 

14. Use of the StringBuilder class
StringBuilder. Append is much faster than String + String.

We recommend that you use the StringBuilder. Append method when the number of connections is greater than three times. You can also use String. Concat

 

15. Disable ViewState
If you do not use form data return, disable viewsate. The control automatically opens viewstate to 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 applications take advantage of application efficiency by page. Each time you try to display a small amount of data, this will speed up page display.Please be careful when using the hybrid cache. Please do not set all data in the cache area.

17.use appoffline.htm when updating applications
Replacement to replace it.

 

18. The control uses ControlState instead of ViewState.

 

19. Use finally to reclaim Resources
If you are using a large number of database connections and access files in the application, please be sure to close them after use.

The finally block is the final execution in the program. Therefore, the code in the finally block will certainly be executed. to close the code, you must execute it in this method block.

20. strictly follow the above steps

Related Article

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.