Develop high-performance ASP. NET Web applications require not only high-quality code, but also many other considerations. This article will briefly discuss and summarize the considerations for developing high-performance Web applications:
1. Avoid unnecessary round-trip transmission to the server. In general, there are many times when we do not need to pass the information to the server for processing. In this case, we should avoid using the code that leads to the transfer of the information to the server, this not only improves the web page performance, but also improves the user experience. In short, the functions that can be completed using client controls and Javascript do not use server-side controls.
2. Remember to use the IsPostBack attribute of the Page object to avoid unnecessary round-trip handling.
3. Only save the view status of the server control when necessary. By default, ASP. NET enables view status for all server controls. If the server control is bound to the data on each round-trip of the Data parameter, because the control value is updated every time, it is useless to save the view status. In this case, the view should be disabled. You can set the EnableViewState attribute of the control to false to disable the control view, or use the @ Page command to disable the view State of the entire Page.
Code: <% @ Page EnableViewState = "false" %>
4. Keep the cache open unless you have to disable it for special reasons. It is a topic about how to select a good cache policy in an application. All asp.net programmers should learn to use the cache policy efficiently.
5. Use the Server. Transfer () method whenever possible for redirection between different asp.net pages in the same application. The following compares the advantages and disadvantages of the Response. Redirect () method and Server. Transfer () method:
1. Response. Redirect can switch to any existing webpage.
2. Server. Transfer can only switch to a webpage in the same directory or subdirectory.
3. 302 redirection is opposed by search engines
4. Server. Transfer first saves the POST data on the current page and then executes the new page. Response. Redirect is just a simple reply to a redirection command. Therefore, if the two methods are tested, the Server. Transfer method should use more time than the Response. Redirect method.
5. Server. transfer () can complete other functions. For example, you can access server control in the previous Web Form in the next Web Form. For example, WebForm1.aspx has a text box named TextBox1, you use preserveForm to pass to WebForm2.aspx with True, and you can still use Request. form ("TextBox1") to obtain the value of the text box. This technology is useful for wizard-type multi-page input.
6. Use stored procedures to access data when using SQL Server to store data. Therefore, asp.net programmers should learn to write efficient stored procedures.
7. If the application only reads access data, use the SqlDataReader object instead of the DataSet object. DataBind () of DataSet is a time-consuming operation.
8. Disable debug mode. In the debugging mode, the performance of Web applications will be greatly affected. Therefore, the debugging mode is always disabled before you deploy Web applications or perform any performance tests. Only enable the debugging mode during the development process.
9. Optimize the configuration file. Optimize the configuration files of the Web server and Web application as much as possible to meet your needs. By default, ASP. NET configuration is set to enable the widest set of features and adapt to the most common situations.
10. Do not add any exceptions in the code During encoding. It is not to say that exceptions should not be used. All possible exceptions should be caught in the code, but we should try to make exceptions ineffective.
11. Use cache. For frequently accessed data, you can use the cache technology to cache the data. For pages or controls, you can select the page output Cache Technology to cache the data to improve the page response speed.