Before getting started with ASP. NET sessions, let's take a look at some small concepts about ASP. NET sessions:
Session management our traditional asp program is actually a Session connection of dead. The system actually writes a Cookie on our client, when we set the Cookie in the security settings of our browser to Prompt, when we access a page with a Session, a Prompt will appear indicating whether to allow the Cookie, when the Cookie is disabled, our Session will never succeed. for example:
- <%
- Session ("Username") ="Tofu"
- Session ("URL") =Http://www.asp888.net"
- %>
In ASP. in the. NET environment, ASP. NET Session is completely redefined, because the current ASP. NET environment is in the PDC version, so there is no Demo for the Beta1 version. Here, if Beta1 content is involved, it is only introduced in materials and has not been tested by bean curd.
As a matter of fact, for some comrades who do not want to go into depth, tofu said: in fact, ASP. the usage of the NET Session is the same as that of the ASP Session, or even simpler. Because, based on the observation of bean curd, we do not need to continue to consider the status of the cookie option on the client, the Session can be smoothly transmitted regardless of the client settings.
Next, let's take a look at the ASP. NET Session usage mechanism in a simple and in-depth manner. Due to technical limitations, I am not very clear about some of the issues. So we welcome you to discuss this article together.
In the PDC version, open the % systemroot % \ complus \ (version) \ config. web file. We can find the Sessionstate to see the previous content:
- ﹤Sessionstate
- inproc="true"
- usesqlserver="false"
- cookieless="false"
- timeout="20"
- server="localhost"
- port="42424"
- /﹥
When inproc is True, ASP. NET will adopt a mechanism called in-process to store Session data on this server. If inproc and usesqlserver are both false, an out process mechanism is adopted, the Session is stored on a server dedicated to saving the Session, which can solve Session sharing when different hosts of a website are accessed, this was absolutely impossible in ASP before. in the Beta1 version, config. the web has changed a lot. Let's take a simple look:
- ﹤!-- Sessionstate attributes:
- mode = "inproc" | "sqlserver" | "stateserver"
- cookieless = "true" | "false"
- timeout = ﹤Session timeout in minutes, a whole number greater than 0﹥
- sqlconnectionstring = ﹤acceptable values for SQLConnection.ConnectionString,
- only used when mode="sqlserver"﹥
- server = ﹤server name, only used when mode="stateserver"﹥
- port = ﹤port number, only used when mode="stateserver"﹥
- --﹥
Let's talk about the Session section of the config. web file. Let's take a look at the cookieless problem:
This Cookieless is not what we usually understand whether to save cookies on the client. According to bean curd observation, ASP. NET Session
No cookie is generated on the browser client.
When we set cookieless to false, let's take a look at this program.
- <%@ Page Language ="VB"%>
- <% Session ("Name") ="Tofu"%>
- <%= Session ("Name") %>
After the program is executed, we don't get any prompts from the browser. Although we also use Session, when we set cookieless to true, we will run this program again, we found that the program is still correctly executed, but the address bar of the browser has changed.
Http: // host/testSession. aspx is now changed to http: // host/(contains many strings)/testSession. aspx bean curd is probably because this Session does not even generate a Cookie on the server, so we have to use (containing many strings) to save the Session content.
When we set both inproc and usesqlserver to false, it means that we will use out process. We need to specify the server name, which is the server that agrees to save the Session, we need to start the asp state service on this server.
When we need to use SQL server, we must fill in the connection string of SQL server, so that the Session will be saved to a database of SQL server, of course, this database is generated ,, however, in the PDC version, I did not find the installation file for this database.
This section describes the usage of ASP. NET sessions. It is helpful to understand ASP. NET sessions.
- Analysis on constructing ASP. NET thread security set
- Introduction to ASP. NET thread security and static variable Lifecycle
- Analysis on the Performance of sessions in ASP. NET
- Introduction to ASP. NET sessions
- ASP. NET Session 7