Maintaining State in a Web Application

Maintaining State in a Web Application The Hypertext Transport Protocol (HTTP) doesn't maintain state between pages served by your Web server during each round-trip | Maintaining State in a Web Application The Hypertext Transport Protocol HTTP doesn t maintain state between pages served by your Web server during each round-trip. This means that any information you provided in a form is for-gotten when you get a new page. If you re simply receiving static HTML Web pages then this isn t a problem. If you re placing an order for a product however then the server needs to remember what you ordered. To get the Web server to remember what you did during the last round-trip you can store information on the server or on the client computer the browser is running on. Storing information on the client means you don t use up any resources on the server to store that information and your Web application can potentially handle many more users. Storing information on the server gives you more control of the stored information but since this consumes server resources you need to be careful not to store too much otherwise your Web application won t be able to handle many users. Storing Information on the Client To store information on the client you can use cookies or the Page object s ViewState property. Let s take a look at how you use cookies and the ViewState property. Storing Information using Cookies A cookie is a name and value pair that is stored in a small file that resides on the hard drive of the client computer. You use the name to identify the value being stored both the name and value are string objects. Warning Cookies are potentially problematic because the user can configure their browser to prevent cookies from being stored. Also a browser stores only a limited number of cookies 300 in total and no more than 20 per Web server. You should therefore use cookies sparingly-if at all. The following example creates an int variable named myInt that is set to 1 and creates an HttpCookie object that stores myInt under the name count int myInt 1 HttpCookie myHttpCookie new HttpCookie count Because a cookie stores the .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
6    98    0
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.