Status management in ASP.NET

xiaoxiao2021-03-19  204

We can easily solve these problems through cookies, query strings, applications, dialogue, etc. in ASP. 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!"; else lbMessage.text = "Welcome Shopping Here! "; If you want to store users, we can use the following code: [c #] response.cookies [" Username ']. Value = username; this way, we can easily identify the user when the user requests the web page. 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 page is submitted to the server, the content of the hidden domain and other control values Send to the HTTP Form collection. The hidden domain can be any repository stored in the web page related to 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 hidden domain features. [C #] protected system.Web.ui.htmlControls.htmlinputhidden Hidden1; file: // assigns hidden1.Value = "this is a test"; File: / / Get a hidden domain str = hidden1.value; it is important to note that the http-post method must be submitted to the Internet page, although its name is a hidden domain, but its value is not hidden We can find its value by "Viewing the Source" function. C, status viewing each control on the web forms page including the web itself has a name for ViewState, it is an automatic web page and control The built-in structure of the state, 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 times between the servers Request - the information during the response. [C #] f ILE: // Save Information ViewState.Add ("Shape", "Circle"); File: // Get Information String Shapes = ViewState ["Shape"]; Note: Different from the hidden domain, in use View Source Code When the value of the ViewState property is invisible, they are 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 directories and product information by the following code: [C #] string categoryid, productId; categoryId = request.params ["categoryID"]; productId = request.params ["productID" ]; Note, we can only submit the Internet page with http-g, otherwise you cannot get the required values ​​from the query string. 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 users, we can see it in the address bar of IE:

http: // localhost / management /

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

New Post(0)