(Domestic version)
Many people will think of using cookies (Httpcookies) To store certain data, so that the stored data can still be read from the user end when visiting another webform. However, if the user's browser does not allow cookies... Isn't that all done... Moreover, cookies can only contain 4 K bytes of data!
Dim Democookie As New Httpcookie ( " Samplecookie " )
Dim Time As Datetime = Datetime. Now
Democookie. Values. Add ( " Time " , Time. tostring ())
Democookie. Expires = Time. adddays ( 5 )
Response. Cookies. Add (democookie)
Response. Redirect ( " Sample. aspx " )
Therefore, we need to use the SQL database of the server side instead of the cookies of the client side. What's more, it is very simple to use the SQL database, just install it. installsqlstate provided by net framework. SQL script and modify the web. config file. The others are exactly the same as the session variables normally written.
Installsqlstate. SQL can be found inC: \ windows \ Microsoft. NET \ framework \ (Version Number )\Folder.
The sessionstate attribute in Web. config to be modified is as follows:
< Sessionstate
Mode = "Sqlserver"
Stateconnectionstring = "TCPIP = FIG: 42424"
Sqlconnectionstring = "Data Source = localhost; Integrated Security = true"
Cookieless = "False"
Timeout = "20"
/>
Set the original
1. Change Mode = inproc to mode = sqlserver.
2. Modify the sqlconnectionstring, but you do not need to enter the initial catalog here. Because aspstate is the mo-person catalog,
This is also the ASP state management database installed by installsqlstate. SQL.
3. Change timeout to the expected session expire value. The unit of timeout is measured in minutes.
4. cookieless = "false" indicates that the sesionid is contained in the URL, for example, http: // server/(sessionid)/sample. aspx.
Therefore, the value of this attribute is generally false.
Dim Time As Datetime = Datetime. Now
Session ( " Time " ) = Time. tostring ())