Brief Introduction to ASP. NET Session Model

Source: Internet
Author: User
Tags what is asp

What is ASP. NET Session? Simply put, it is the number that the server sends to the client. When a WWW server is running, several users may browse the website running on this server. When a user establishes a connection with the WWW server for the first time, the user establishes a Session with the server, and the server automatically assigns a SessionID to the user to identify the unique identity. This SessionID is a random string consisting of 24 characters on the WWW server. We will see it in the following experiment.

This unique SessionID has great practical significance. When a user submits a form, the browser automatically attaches the user's SessionID to the HTTP header, which is an automatic function of the browser and is invisible to the user ), after the server processes the form, it returns the result to the user corresponding to the SessionID. Imagine how the server knows which user submitted the form when two users register simultaneously without SessionID. Of course, SessionID has many other functions, which we will mention later.

In addition to SessionID, each Session contains many other information. However, for asp or asp.net programming and programming, the most useful thing is to access asp/asp.net Session objects and store their respective information for each user. For example, if we want to know how many pages a user visits our website browses, we may add the following to each page that a user may access:

 
 
  1. < %  
  2. If Session("PageViewed") = ""Then  
  3.  Session("PageViewed") = 1  
  4. Else  
  5.  Session("PageViewed") = Session("PageViewed") + 1  
  6. End If  
  7. %>   
  8.  

You can use the following sentence to learn about several pages you have browsed:

 
 
  1. < %  
  2. Response.Write("You have viewed " & Session("PageViewed") & " pages")  
  3. %>  
  4.  

Some readers may ask: where does this seemingly array Session ("...") come from? Do I need to define it? In fact, this Session object is a built-in object of the WWW server with asp interpretation capability. That is to say, this object has been defined for you in the asp system, and you only need to use it. The variable name in Session ("...") is like the variable name. The $ in Session ("...") =$ $ is the variable value. You only need to write a sentence to access the value in the variable .. on every page of the user.

In fact, asp has a total of seven built-in objects, including Session, Application, Cookie, Response, Request, Server, etc. Similar objects are also available in other server-side scripting languages such as JSP and PHP, but they are not the same in terms of naming or usage.

The above are some basic concepts of ASP. NET Session.

  1. ASP. NET array basics: declarations, representations, and examples
  2. Top 10 skills in ASP. NET Programming II)
  3. Top 10 skills in ASP. NET Programming 1)
  4. ASP. net mvc tutorial (1): Preparations
  5. Deployment of ASP. net mvc Beta

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.