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:
- < %
- If Session("PageViewed") = ""Then
- Session("PageViewed") = 1
- Else
- Session("PageViewed") = Session("PageViewed") + 1
- End If
- %>
-
You can use the following sentence to learn about several pages you have browsed:
- < %
- Response.Write("You have viewed " & Session("PageViewed") & " pages")
- %>
-
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.
- ASP. NET array basics: declarations, representations, and examples
- Top 10 skills in ASP. NET Programming II)
- Top 10 skills in ASP. NET Programming 1)
- ASP. net mvc tutorial (1): Preparations
- Deployment of ASP. net mvc Beta