Skills for improving the performance of Asp.net applications
Source: Internet
Author: User
1. Eliminate multiple data binding controls
Add if (! Page. ispostbck) statement, so that the binding is performed only when the page is loaded for the first time, and the page cannot be bound again when the page is sent back.
BIND in the prerender method. After the prerender event occurs after the send-back event, bind it to the prerender event after processing the event to be processed in the previous event (init, load, postbackevent, in this way, the control is repeatedly bound to multiple sending events. This method is only used when multiple sending events need to be repeatedly bound to the control, this is because the prerender event is triggered every time it is sent back.
2. Minimize the viewstate size.
Viewstate is used to save the status of the Web Server Control and restore the value of the control when the page is sent back. if we use HTML controls instead of Web Server Control, the viewstate size will be effectively reduced, so that the page size will be reduced.
When using Web Server Control, if you only bind data once during page initialization or re-bind data each time the page is sent back, viewstate is not used in this case, set the enabledviewstate attribute of the control to false. in particular, some controls that use templates, such as DataGrid and datalist. disabling viewstate for template controls can effectively improve performance.
3. server. Transfer and response. Redirect
If possible, try to use server. the transfer method replaces response. redirect method. response. redirect sends a Response Header (reponse heaer) to the client to send a new URL request to the server. server. the transfer method can avoid sending and re-sending requests. It simply implements server-side redirection.
Of course, this replacement cannot be used at all times, because server. the transfer method uses a new handler to handle new requests. if you need to verify and authorize access to the redirected page, you should use response. redirect method. because they have different mechanisms. when you use response. when using the Redirect method, you must first determine that you are using the bool-type overload method with the second parameter and set this parameter to false to ensure that no internal exception is thrown. another thing to note is that you can only use server. transfer to pass the control to the same application ProgramTo pass the control to another application page, you must use the response. Redirect method instead of the server. Transfer Method.
The server. Transfer Method transfers the execution process from the current aspx file to another ASPX page on the same server. When server. Transfer is called, the current ASPX page is terminated and the execution process is transferred to another ASPX page. However, the new ASPX page still uses the response stream created on the previous ASPX page.
If you use the server. transfer method to implement navigation between pages, the URL in the browser will not change because the redirection is completely performed on the server side, and the browser does not know that the server has executed a page transformation.
By default, server. the transfer method does not pass form data or query strings from one page to another, but you only need to set the second parameter of this method to true, the form data and query string of the first page can be retained.
At the same time, use server. note that the target page will use the response stream created on the original page, which leads to ASP.. Net machine authentication check (MAC), The viewstate of the new page is deemed to have been tampered. Therefore, to retain the form data and query string set of the original page, you must set the enableviewstatemac attribute of the target page command to false.
For details, see http://blog.csdn.net/aaahts/archive/2004/07/26/51786.aspx. ArticleThese methods are described in detail.
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