Performance Analysis of Asp.net

Source: Internet
Author: User

This course was intended to be shared with our group members. We have learned this course online today because of the lack of time.
1.
  Viewstate
Viewstate is a feature of Asp.net. It is used to save a state value used to generate a page in a hidden domain. When the page is uploaded back to the server, the server needs to parse, verify, and apply the data in viewstate to restore the control tree of the page. Viewstate is a very useful feature that can persist the client state without the cookie or server memory. Most server controls use viewstate to persist the status values of elements that interact with users on the page. • Viewstate may have some negative effects. First, it increases the server response and request time. Second, the serialization and deserialization of data are added each time the data is returned. Finally, it consumes more memory on the server. • Disable the viewstate of the specified page;

 

You can disable the viewstate of the entire web through webconfig.

<Configration>
<System. Web>
<Pages enableviewstate = "false"/>
</System. Web>
</Configuration>

The viewstate encoding method uses base64 encoding.

• Enableviewstatemac attribute representation:
If ASP. NET runs the message Verification Code (MAC) in the view status of the page when the page is sent back from the client TrueOtherwise False. Default Value: False. • View State Mac is the encrypted version of the Hidden variable that is saved when the view State of the page is sent to the browser. If TrueCheck the encrypted view status to verify that the view status has not been tampered with on the client. If you primarily consider performance, do not set EnableviewstatemacSet True .If the page view is tampered with, the page will no longer be used to restore the page.
2. page Jump Performance
Request Process:
1) browser aspx file request ---> server execution ---> response. Redirect statement-> the server sends the address following response. Redirect to the client browser ---> the browser requests a new address.
2) browser aspx file request-> server execution-> server. Transfer statements-> server redirection to new files
You can see that server. Transfer is less than response. Redirect in the process of sending back from the server and re-requesting from the client.
Jump object:
1) response. Redirect can switch to any existing webpage.
2) server. Transfer can only switch to webpages in the same directory or subdirectory.
Data Confidentiality:
1. After response. Redirect, The address will change to the page address after the jump.
2. The address remains unchanged after server. Transfer, hiding the address of the new web page and the parameter values attached to the address. Data Confidentiality.
Transmitted data volume (parameters attached to the URL ):
1. The data that response. Redirect can pass is limited to 2 kb (that is, the maximum length of the address in the address bar.
2. When the transmitted data exceeds 2 kb, you must use server. Transfer.
3. Performance in sessionstate
Improve the closing session Status of ASP. NET applications. If ASP. NET is not used, disable the session Status of the page. You can set it in the @ page command:

<% @ Page Language = "C #" enablesessionstate = "false" %>

If this attribute is set, a page exception is thrown when you try to set or retrieve session variables. we recommend that you disable the session status for any page that does not require access to the session variable, depending on the page size, this will significantly increase the page loading time, because ASP. net will not process ASP. net session.
If the page requires access to session variables but never operates on these variables, the sub-optimal setting of enablesessionstate is "readonly ". that is to say, they can be accessed, but they cannot be set. the performance growth caused by this is not as big as the state of fully disabled sessions, but better than enabling all session state management. If you try to set a known variable when this attribute is set, an exception will be thrown. you can use webconfig to disable the entire web session status. code
1 <configration>
2 <system. Web>
3 <sessionstate mode = "off"/>
4 </system. Web>
5 </configuration>

Summary:
1. do not use server controls when you do not need to interact with controls programmatically during server events. that is to say, if the information is static in nature, you do not need to interact with it, or you do not need to reference it from the server code. standard HTML should be used. this reduces the code size, the number of event handlers, the size of view states, and the total size of page classes-all of which can improve ASP. net web page performance.
2. If this is not required, disable the session Status of any page or entire website.
3. Close the view status of any page or entire website if you do not need it.
4. Do not forget to disable debugging.
5. explicitly calling the dispose method tells ASP. NET to quickly collect unused inner information, and the explicit request to reclaim the memory can help the garbage collection process.
4. Use of page Cache
Using page cache can greatly improve the performance of our program. 1 <% @ outputcache duration = "60" varybyparam = "*" %>
2

In this example, the user control is cached for 60 seconds, and a separate cache entry is created for each change of the query string and for each page where the control is located.
"*" In varybyparam indicates that different pages are cached based on different parameter values. "None" indicates that only the request results are cached during running, and query characters or form parameters are not used;
Another problem is that I cached the entire page, but some content on this page needs to be displayed in real time. How can this problem be solved? For example, on the current page, I want to display how many people have accessed this page. Use the substitution control to specify that the dynamic content of the output cache page should be replaced by the control. The substitution control provides a simplified solution for caching partial pages for pages that require most of the content to be cached. You can cache the output of the entire page, and then use the substitution control to specify the part on the page that is exempt from caching. When the substitution control is executed, a method to return a string is called. The string returned by this method is the content to be displayed on the position of the substitution control on the page. Use the methodname attribute to specify the name of the callback method to be called when the substitution control is executed.
Criteria that must be met when substitution is used:
1. This method must be defined as a static method.
2. This method accepts parameters of the httpcontext type.
3. This method returns a value of the string type.

Note: substitution cannot access other controls on the page. That is, the value of other controls cannot be checked or changed.

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.