At the underlying layer, the. NET and ASP. NET infrastructures have done a lot of basic work to make development easier. Although this architecture is good as a black box, it is helpful to understand the implementation details of the operation, and to effectively use the runtime to obtain performance advantages.
1. View status Optimization
You can control the view status of a website at different granularities: on the web. config sets enableviewstate to false to disable viewstate for all pages. The enableviewstate attribute of the page inherits from the web. config settings. You can set enableviewstate on a separate page. In addition, you can set the enableviewstate of the control separately.
Web. config: pages enableviewstate = " false " />
page: <% @ page Language =" C # "codebehind =" default. aspx. CS "inherits =" default "enableviewstate =" false "%>
Control: Asp : label id = " lbinfo " runat = " server " enableviewstate = " false " />
2. Minimize the number of server controls
The number of controls on the server on the page should be kept at the lowest level. The controls on the server not only generate the view status, but also need additional runtime processing to bind to the member variables, render them, and uninstall them. Do not use server controls.
3. session Status considerations
Create a web applicationProgramA major problem is that page requests are directly maintained because HTTP requests are stateless. For example, you can know what products the customer has placed in the shopping cart. There are many mechanisms that can be used together to obtain the persistence of the State: cookies, view status, querystring, session.
ASP. NET provides three different session Status providers (in-Proc, status server, and database), greatly improving the session function. The inter-process session Status provider is the fastest among the three. Although the status server is not as fast as the inter-process, it can directly share the session status on multiple servers. Database storage is the most robust but slowest.
No matter which session Status provider is used, do not misuse the session function to store a large amount of data or objects. The definition of "A large number" depends on the number of users to be supported and the hardware of the application. If you do not use a session on some pages, you can disable the session on the page and set enablesessionstate to false, which can also slightly reduce the overhead of the page.
4. minimize exceptions
Exceptions are a very useful mechanism for notifying programs of errors occurring during execution. And returnCodeDifferent programs cannot ignore exceptions-they will change the execution flow of programs. Avoid extra overhead in applications with critical performance and memory. In the managed environment of. Net runtime, setting Exception Handling Code with try and catch only has negligible impact on performance. However, if an exception is thrown, the performance loss is high.
5. Use early binding
Pre-binding determines the data to be bound during compilation. If pre-binding fails, a compilation error will be reported during compilation to avoid compilation errors during runtime. Later binding fills in data during running, and later binding fails only during running. Www.126fm.net