Status management in ASP.NET

xiaoxiao2021-03-06  21

Status management in ASP.NET

Author: Unknown Updated: Legume Source: Unknown Updated: 2004.08.24 Contributor mail: tg * ddvip.com in ASP we can easily solve these problems by cookie, query strings, application, dialogue. Now in the ASP.NET environment, we can still use these features, but they are more types, and the functions are more powerful. There are two different ways to manage Internet webpages: clients and server. 1. Status Management of the Client: In the client, multiple requests between the servers - the response does not save information on the server, the information will be stored on a web page or user's computer. A, cookie cookies are a small amount of data stored in the text file of the client file system or the memory of the client browser conversation, which is primarily used to track data settings. Below us, however, suppose we want to customize a welcome Internet page. When the user requests the default Internet page, the application will first check if the user has been registered before, we can get the user from cookies: [c #] IF (Request.Cookies ["UserName"]! = null) lbMessage.text = "dear" Request.cookies ["Username"]. Value ", Welcome Shopping Here!"; elselbMessage.Text = "Welcome Shopping Here!" If you want to store the user's information, we can use the following code: [c #] response.cookies ["username ']. Value = username; this way, when the user requests the web page, we can easily identify the user. B. The hidden domain hidden domain does not appear in the user's browser, but we can set its properties like setting the standard control. When a web is submitted to the server, the content of the hidden domain and other control values ​​are Send it to the HTTP Form collection. The hidden domain can be any repository that stores information related to the web page in the web page, and the hidden domain stores a variable in its value attribute, and must be explicitly added on the web page. ASP. The HTMLINPUTHIDEN control in NET provides a hidden domain. [C #] protected system.Web.ui.htmlControls.htmlinputhidden hidden1; file: // assigns hidden1.Value = "this is a test"; file: // Get a hidden domain for the value str = hidden1.value; it is important to note that the HTTP-POST method must be submitted to the Internet page, although its name is hidden, but its value is not hidden, We can find its value through the "View Source" function. C, the status view includes each control on the web forms page, including the web, has a name for ViewState, which is an automatic page and control status. The built-in structure, which means that after submitting a web page to the server, we do not need to take any steps to restore the control data. Here, for us is the ViewState property, we can use it to save multiple requests between the servers - Information during your answer. [C #] file: // Save Information ViewState.Add ("Shape", "Circle"); File: // Get Information String Shapes = ViewState ["Shape"]; Note: Different from the hidden domain, when you use the View source code function, the value of the ViewState property is invisible, which is compressed and encrypted.

D. The query string query string provides a simple and restricted maintenance status information. We can easily pass the information from a web page to another web page, but most browsers and client devices use URLs. The length is limited to 255 characters. In addition, the query value is passed to the Internet via the URL, so in some cases, security has become a big problem. URL with query string as follows: http://www.examples.com/list.aspx?categoryId=1&productId=101 After the client requests list.aspx, you can get directory and product information by the following code. : [C #] string categoryId, ProductId; categoryid = request.Params ["categoryID"]; ProductId = Request.Params ["ProductID"]; Note that we can only use HTTP-GET to submit the Internet page, otherwise you can't query from query String gets the value you need. 2, the status management information of the server side is stored on the server, although its security is high, it will take up more web server resources. A, APLICATION object APLICATION object provides a mechanism that allows all code access to code accessed in a web application server, and inserts data inserted into the application object status variable should be shared by multiple conversations, and will not change frequently. It is precisely because it can be accessed by all applications, so we need to use Lock and Unlock to avoid conflicts. [C #] Application.lock (); Application ["MyData"] = "mydata"; Application.unlock (); b, session object session object can be used to store multiple requests that need to be in the server and to web pages The information of the specified dialog for maintenance during the request. The session object is the basis of the existence of each conversation, that is, different clients generate different session objects. The period of data stored in the conversation status variable is shorter. The ASP.NET conversation of each activity is uniquely determined and tracked by a SessionID string containing legitimate URL ASCII characters with a length of 120. The value of SessionID is generated by an algorithm that guarantees uniqueness so that the conversation will not conflict, and the parasis of sessionid makes it difficult to guess the ID of the existing dialogue. Depending on the configuration settings of the application, the sessionID is transmitted between the client-server request via HTTP cookie or the modified URL. So how do you set the dialogue equipment method for the application configuration. Each web application must have a named web.config configuration file, which is based on an XML file. Below is a dialogue named sessionState: The value of the cookieles option is TRUE or FALSE. When its value is false (default), ASP.NET will use HTTP cookie to identify users; when its value is TRUE, ASP.NET will randomly generate a unique number and put it in requested. In front of the file, this number is used to identify the user, we can see it in the address bar IE: http:// localhost / management / (2yzakzez3eqxut45ukyzq3qp) /Default.aspx OK, let's go back to the session object .

转载请注明原文地址:https://www.9cbs.com/read-43386.html

New Post(0)