Analysis of ASP. NET Session usage

Source: Internet
Author: User
Tags net thread

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:

 
 
  1. <%
  2. Session ("Username") ="Tofu" 
  3. Session ("URL") =Http://www.asp888.net" 
  4. %>

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:

 
 
  1. ﹤Sessionstate  
  2. inproc="true" 
  3. usesqlserver="false" 
  4. cookieless="false" 
  5. timeout="20" 
  6. server="localhost" 
  7. port="42424" 
  8. /﹥ 

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:

 
 
  1. ﹤!-- Sessionstate attributes:  
  2. mode = "inproc" | "sqlserver" | "stateserver" 
  3. cookieless = "true" | "false" 
  4. timeout = ﹤Session timeout in minutes, a whole number greater than 0﹥  
  5. sqlconnectionstring = ﹤acceptable values for SQLConnection.ConnectionString,  
  6. only used when mode="sqlserver"﹥  
  7. server = ﹤server name, only used when mode="stateserver"﹥  
  8. port = ﹤port number, only used when mode="stateserver"﹥  
  9. --﹥ 

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.

 
 
  1. <%@ Page Language ="VB"%>
  2. <% Session ("Name") ="Tofu"%>
  3. <%= 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.

  1. Analysis on constructing ASP. NET thread security set
  2. Introduction to ASP. NET thread security and static variable Lifecycle
  3. Analysis on the Performance of sessions in ASP. NET
  4. Introduction to ASP. NET sessions
  5. ASP. NET Session 7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.