您的位置:首页 > 移动开发

10 Tips to Improve an ASP.NET Applications Performance

2015-06-10 14:26 423 查看
In developing .NET applications, there are a few things that can be done, or avoided, to make significant and noticeable improvements in performance. Here are a few that are worth implementing:
Caching: 

If your application is processing quite a bit of information, mostly static, avoid getting that information when it’s not needed. For example, getting certain key values in the web.config file.

Response.Redirect vs. Server.Transfer: 
Response.Redirect sends quite a bit of information to the server and should be used when transferring/posting to another physical server. Server.Transfer however, only posts
the form information and not the entire page. It also loads pages faster and should be used for transfers within your server.

Avoid Exceptions?: 

As much as they help with catching those elusive bugs, throwing exceptions can add significant overhead to your application. Check for conditions that may cause exceptions before throwing them and use them when absolutely necessary.

Use Page.IsPostBack to minimize processing: 

Using Page.IsPostBack can help in reducing the amount of redundant processing and execution of code that’s only needed once, for example, when a page loads.

StringBuilder: 

If you’re working with very large strings, use StringBuilder.Append as opposed to string += string (orString.Concat), it’s faster.

Turn Off ViewState: 

If you’re not posting back to a form, turn off ViewState as it slows the loading of pages.

Paging: 

If you’re going to show dynamically generated data in your application, use the paging capabilities of .net to display small set of data at any given time.

Client-Side vs. Server-Side Validation: 

Avoid using server-side validation where it’s not needed and use client-side validation instead.

Use Release Build: 

When deploying your application to the production site, make sure to not use the Debug Build as running in debug mode slows your application down.

And finally (not quite): 

Utilize the finally block as best you can as it is the only block of code that is guaranteed to be executed. Any open database connections, text readers, files etc. should be closed here to reduce the number of resources left unhandled that
can slow your application down.

These are just a few additions that can help when it comes to improving applications performance. There are many many more out there, but thesesare the ones that we should try to implement on a daily basis when developing applicaitions.

Happy coding!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ASP.net