Tips for improving the performance of. Net Applications

Source: Internet
Author: User
Make changes in the web. config and machine. config files.

1. Set debug to false <Compilation DEBUG = "false"/>

This property is true by default when a program is created, but false by default in vs2005. This property is true during development to facilitate debugging.

2. Turn off page tracking
Debugging and tracing must be disabled when you deploy a program. <Configuration>
<System. Web>
<Trace enabled = "false" pageoutput = "false"/>
<Trace enabled = "false" requestlimit = "10" pageoutput = "false" tracemode = "sortbytime" localonly = "true"/>
<Compilation DEBUG = "false"/>
</System. Web>
</Configuration>

3. Disable session
Asp.net automatically manages the session status. If you do not need a session, disable it. <Sessionstate timeout = "20" cookieless = "false" mode = "off" stateconnectionstring = "TCPIP = 127.0.0.1: 42424"
Sqlconnectionstring = "Data Source = 127.0.0.1; trusted_connection = No">

Or set it on the page. <% @ Page enablesessionstate = "false" %>

If the session is disabled in Web. config, the session cannot be enabled on the page.

What we should do when building a. Net Program

4. Select the release mode when compiling the final release version.
Common Methods to Improve Performance

5. disable unnecessary viewstate

6. Avoid frequent Database Access
Connecting to the Database Multiple times is very performance-consuming. You can use batch processing to obtain the required information.
The database access times should be introduced as much as possible. If many connections are not closed, the performance will be seriously affected. Using dataadapter, it will automatically open and close the database connection.

7. Avoid throwing exceptions and performance consumption

8. Use Cache

9. Use the appropriate Authentication Mode
The authentication mode is set to none Windows Forms passport.

10. Verify all user input
Verify on the client and server

11. Use finally to recycle Resources
Use the finally method in the try catch statement to Close opened connections, datareaders, files, or other resources.

12. Use stringbuilder

13. Avoid recursive functions

14. Set the page strict and explicit to true.
VB.net option, strict = true does not allow type conversion that may result in data loss. Explicit = true all variables must be stated in advance

15. Use early binding in VB and JScript to declare the type

16. Use response. Write for string connection
When multiple strings need to be connected to the output, multiple calls to response. Write are faster than a single call to response. Write.

17. Use Page. ispostback to avoid additional page processing.

18. Keep the IO buffer size between 4 kb and 8 KB

19. Use less format ()

20. Optimized expression
For example, use exp + = to replace exp = exp + val.

21. Use return in Function

22. Use for loops for string Iteration

23. Display dispose or close all resources Try
_ Con. open ()
Catch ex as exception
Throw ex
Finally
If not _ con is nothing then
_ Con. Close ()
End if
End try

24. Pre-compile page and disable autoeventwireup

Database
1. Use the appropriate provider

2. Use stored procedures

3. Replace dataset with sqldatareader

4. Disable unused features
Disable Automatic transaction enlist Sqlconnection conn = new sqlconnection ("Server = mysrv01; Integrated Security = true; enlist = false ");

5. Minimize data in Dataset

6. Use the connection pool and Object pool

Http://www.codeproject.com/useritems/NET_Tips_and_tricks.asp

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.