[Study Notes] ASP. NET application performance optimization

Source: Internet
Author: User

ASP. NET application performance optimization

I. Page and server processing
1. Avoid round-trip with the server
Eg: A. Read a large amount of data at a time, and submit it to the intended database after processing by the client;
B. Ajax: the front-end page is not refreshed. Separate threads interact with the server. Reducing server round-trips can improve performance.
2. Use ispostback to avoid additional operations during round-trip
Page event process: page_preinit-> page_init-> page_load-> control events-> page_prerender-> page_unload
Any page loading requires a complete page process. Using ispostback can filter some steps.
3. Use server-side controls with caution
The server control encapsulates some events, making them more overhead. You can consider using HTML controls.
4. View status viewstate
Disable the attempt status of the entire page <% @ enableviewstate = "false" %>. You can also disable the attempt status of the specified control.
Ii. Status Processing
1. Disable painting status
A. disable a session when it is not in use
<% @ Page enablesessionstate = "false" %>
B. Read-only painting
<% @ Page enablesessionstate = "readonly" %>
C. Disable the nonsense status of Web Service
[Webmethod (false)]
[Wevmethod (enablesession = false)]
D. Disable application painting.
<Sessionstate mode = "off">
2. Carefully select the session Status provider
A. Painting status in process
Asp.net default mode, the fastest speed.
Using only a small amount of data that is easy to lose in the session state will not have a great impact on the application.

In web. config, <sessionstate mode = "inproc">
B. Windows Service non-process session Status
In web. config, <sessionstate mode = "StateServer" stateconnectionstring = "TCPIP = localhost: Port Number">
C. Non-process session Status in the SQL Server database

In web. config, <sessionstate mode = "sqlserver" allowcustomerdatabase = "false" stateconnectionstring = "database = database name/sql2005; uid = sa">

On the console: aspnet_reg.exe-s Database Name \ sql2005-u-ssad-sstype P

Iii. Data Access

1. Use stored procedures for data access
2. Use sqldatareader to obtain the fast forward read-only data cursor
3. cache data and page output as much as possible

Consider using page cache for pages that do not require dynamic computing output
Note: A. Do not use too much cache (occupying Server Memory)
B. the cache time cannot be too short.
4. Web reference program
1. Large applications, pre-compiled first
2. Adjust the number of threads for each application process when necessary
3. Disable debugging mode
4. Optimize the application configuration file
A. Whether authentication is required
B. character set (the whole site uses ASCII and is configured as UTF-8 to slightly improve performance)
C. Clear unnecessary modules in httpmodual
5. coding Optimization
1. Do not rely on exception capture in the code, and use judgment to handle it
2. Use stringbuilder to link a large number of strings
3. Do not use too much memory
4. Try to avoid using the Finalize method object and rewrite the dispose method.

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.