Research and discussion on optimizing asp.net application performance

Source: Internet
Author: User
Tags html tags server memory

The performance of a Web site is very important for asp.net developers. Although a good site has beautiful page design, perfect service function, but open the page has a long delay, the user will eventually unbearable. Especially for large e-commerce sites, there are tens of thousands of users per second access, no good site performance, simply can not meet the huge demand.

Asp. NET as a new generation of Dynamic Web page generation system, it has an essential improvement in platform performance compared with the original ASP. But on this basis to develop professional standards, meet the standards of production, user-welcome Web applications, but also need developers from a programmatic point of view in the page, data access and string processing and other aspects of the optimization process to improve the overall performance of the site.

In this paper, we will discuss several methods of performance optimization in asp.net and pay attention to the problems concerned.

Page Performance Optimization

1, the appropriate choice of session state

The HTTP protocol is a stateless communication protocol that cannot record and identify requests from different clients, but in practice the system maintains session state information between different requests from the client. Asp. NET solves this problem by storing session state information in a process, state server, or SQL Server database.

Saving session state information in the memory of a Web server has the best performance and speed, but lacks the ability of session state information to span multiple servers. To maintain session information between multiple Web servers, you can use a state server for storage, which increases the scalability and reliability of your system by deploying applications to multiple servers, but at the expense of performance. For extremely important session information, you need to use SQL Server storage to avoid losing important session information, but the resulting workload is much larger than the previous two.

If you do not consider the retention of state information and multiple server sharing, you should choose to save in the process of the server in order to get the best performance.

The way in which session state information is stored is selected through the Web.config file:

<sessionState
mode="InProc/StateServer/SqlServer" //存储方式由此行选择
stateConnectionString="tcpip=127.0.0.1:42424"
……
timeout="20"/>

2, server control optimization selection

2.1 Reducing unnecessary server controls

The convenience and functionality that the server control brings is unmatched by the HTML control. However, each server control needs to create the appropriate object on the server side, at the expense of server-side resources, excessive use of server controls can greatly affect program performance.

In many cases, simply using HTML tags or data binding enables you to achieve the desired functionality. For example, a <asp:Label> control, if used to display static information, can be fully implemented with simple tags. If the HTML control does not reach the functionality you want to implement, and you cannot implement it in a scripting language such as JavaScript or VBScript, consider selecting a server control.

2.2 Disabling unnecessary view of status

The State view properties of the server control can automatically maintain the state of the server control during a round trip, reducing the developer's workload, but requiring a large amount of server memory resources. Therefore, you should set its EnableViewState property to false, such as a commonly used <asp:Lable> and <asp:Button> control, without requiring a server control state view.

The application of 2.3 page.ispostback

Page.IsPostBack is used to record whether the page is returned from the client, or false for the first run, otherwise the page is returned from the client. The reasonable application of page.ispostback can avoid some unnecessary operation of the page in the round trip process. This property can be used to improve application performance in the Page_Load function and in some event functions that need to be initialized only once.

void Page_Load(Object o, EventArgs e)
{
  if(! Page.IsPostBack)
  {
   conn=new SqlConnection("server=localhost;uid=sa;pwd=;database=data");
   String sql="select * from student";
   cmd.Fill(ds,"stu");
   mydataGrid.DataBind();
  }
}

The above code will ensure that the database is read and bound only when the page is first accessed.

Related Article

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.