Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to improve the performance of ASP.NET Web Application

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to improve the performance of ASP.NET Web application, which is very detailed and has certain reference value. Friends who are interested must finish reading it!

1.debug = "false"

When creating an ASP.NET Web application, the default setting is "true". Setting it to "true" is very useful during development, but when the application is released and deployed, it needs to be set to "false".

two。 Turn off tracing (tracking)

Tracing is very scary, have you forgotten to turn it off? If it doesn't work, be sure to edit web.config and close it. It will take up a lot of your program resources.

3. Disable session

If you don't need session session tracking, be sure to disable it. You can set the following in each asp.net page:

4. Deploy applications using the release version

When deploying an application to a production environment, make sure that you use the release mode, not the debug mode. Request timeouts can easily occur if you use debug templates. When deployed as a release, you will find that the speed has been greatly improved.

5. Close the View State of the page

View State is mainly used after submission, and it is useful only if the data on the page is submitted to this page. The default is "true". If you are not using form data backhaul, you can turn off View State.

6. Avoid using Response.Redirect

Redirect (redirect) is very troublesome and is only used to jump from current physical server development to other servers. If you are only redirecting pages within the development of this server, please use the Server.Transfer syntax, which will reduce a lot of unnecessary client redirects.

7. Using the StringBuilder class and the ToString () method

The String class object is immutable, and the reassignment of the String object essentially recreates a String object and assigns the new value to it, and the performance improvement of its method ToString is not significant. When working with strings, it is best to use the StringBuilder class, whose .NET namespace is System.Text. Instead of creating a new object, this class directly manipulates the string through methods such as Append,Remove,Insert, and returns the operation result through the ToString method. The definition and operation statements are as follows

Int num; System.Text.StringBuilder str = new System.Text.StringBuilder (); / / create the string str.Append (num.ToString ()); / / add numeric num Response.Write (str.ToString); / / display the operation result

8. Avoid throwing exceptions

Exceptions cause it to slow down and cause the application page to display exceptions, making it impossible to do anything else. You can use try / catch to log any exceptions that occur.

9. Using the finally method to recover resources

If you use a lot of other database connections and access files in your application development, be sure to close them after you use them. The finally block is the last to be executed in the program, so the code in it ensures that it will be executed, and the closing code must be executed in this development method block.

10. Validate using client script

Use client-side authentication instead of server developer-side verification. Server developer data validation will consume a lot of resources on your server development, and will replace a large number of page data back.

11. Use Page.IsPostback

Make sure that you do not execute too much backhaul code. Use the Page.IsPostBack property to ensure that only the page initialization logic is performed when a page is loaded for the first time without posting back to the responding customer.

twelve。 Use paging

Most Web application data is displayed in tabular form. Paging can take advantage of the efficiency of application development. Try to display a small amount of data each time, which will speed up the display of the page.

13. Call asynchronously using Ajax

Use the Ajax method to make an asynchronous call.

14. Delete unused HttpModules

For httpModules, we can understand it by creating a generic HttpApplication event hook that can be plugged into any Web application. Using HttpModule is reusable and does not require language-specific application code, just an entry in web.config. In the web.config file, delete the unused HttpModules.

15. Avoid recursive functions / nested loops

Nested loops and recursive functions need to be avoided in any programming language to improve performance.

16. Do not use unnecessary Server Control

In ASP.NET, a large number of server-side controls facilitate program development, but it may also bring performance loss, because every time the user operates the server-side control, there is a round trip between the server-side control and the server-side. Therefore, it is not necessary to use Server Control less.

17. Use multithreading when invoking multiple operations

When a problem occurs, the single-threaded card runs for a long time on this issue. Therefore, multiple threads can be used to improve the response speed of the application.

18. Connection and closure of the database

Accessing database resources requires several operations: create a connection, open a connection, and close a connection. These processes require multiple exchanges of information with the database to pass authentication, which consumes server resources. Connection pooling (Connection Pool) is provided in ASP.NET to improve the performance impact of opening and closing databases. The system puts the user's database connection in the connection pool, takes it out when needed, withdraws the connection when closed, and waits for the next connection request. The size of the connection pool is limited, and if you still need to create a connection after the connection pool reaches its maximum, it will greatly affect performance. Therefore, after establishing a database connection, the connection is opened only when the operation is really needed, and closed immediately after use, so as to minimize the opening time of the database connection and avoid exceeding the connection limit.

19. Using the SqlDataReader class for fast forward-only data cursors

The SqlDataReader class provides a way to read forward-only data streams retrieved from a SQL Server database. If there is a situation that allows you to use it when creating an ASP.NET application, the SqlDataReader class provides higher performance than the DataSet class. This is because SqlDataReader uses SQL Server's native network data transfer format to read data directly from the database connection. In addition, the SqlDataReader class implements the IEnumerable interface, which also allows you to bind data to server controls. See the SqlDataReader class for more information. For information about how ASP.NET accesses data, see accessing data through ASP.NET.

20. High performance SQL statement rules

Avoid full table scanning as much as possible

Try to avoid judging the null value of a field in the where clause.

Try to avoid using the! = or operator in the where clause.

Try to avoid using or to join conditions in the where clause

In and not in should also be used with caution.

Do not perform functions, arithmetic operations, or other expression operations to the left of the "=" in the where clause

Update statement, if only 1 or 2 fields are changed, do not Update all fields

For multiple tables with a large amount of data (a few hundred are considered large here), JOIN should be paged before JOIN, otherwise the logical reading will be very high and the performance will be very poor.

Use varchar/nvarchar instead of char/nchar whenever possible

21. Caching

Caching is a technology that trades space for time, which means that the data you get is stored in memory for a short period of time, during which the server does not read the database, or the real data source, but reads the data you store in memory. Caching is an indispensable data processing mechanism for website performance optimization, and it can effectively alleviate the pressure on the database. Caching in ASP.NET is mainly divided into:

Page caching

Data source cache

Custom data caching

twenty-two。 Do load balancing and server bonus

Load balancing should not be seen as just a means of achieving scalability. Although it certainly improves scalability, it increases the performance of Web applications in many cases because requests and users distribute multiple servers.

23. Code review and optimization through FxCop

FxCop is a code analysis tool that uses a rule-based engine to detect irregularities in your code; you can also customize your own rules to add to the engine. Some of these rules are:

Avoid too many local variables

Avoid using uncalled private code

Avoid uninstantiated inner classes

Avoid using unsealed features

Avoid unnecessary conversions

Initialize static fields of reference types inline

Mark assemblies with NeutralResourcesLanguageAttribute

Mark members as Static, and so on.

24.ASP.NET performance Monitoring tool

These are tools for monitoring the performance of your code.

.net memory Analyzer

Red Gate ANTS performance Analysis tool

Fiddler

Performance counter

The above is all the contents of the article "how to improve the performance of ASP.NET Web applications". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report