ASP. NET session details 1

Source: Internet
Author: User

Session model Overview

What is 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 information (this is an automatic function of the browser and the user will not notice it ), 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. HoweverProgram The most useful thing is to access the built-in session objects of ASP/ASP. NET to 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. 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.



ASP session functional defects

Currently, ASP developers are using session, but they have discovered the following defects in ASP session:



Process dependency: the ASP sessionstate is stored in the iisprogress, And the inetinfo.exe program is also used. When the inetinfo.exe process crashes, the information is lost. In addition, restarting or disabling the IIS service will cause information loss.

Limitations of the range of session Status usage: when a user accesses another website from one website, the session information will not be migrated. For example, there may be more than one WWW server on the Sina website. After a user logs on, he/she will go to various channels, but each channel is on a different server, what if I want to share session information on these www servers?

Cookie dependency: in fact, the client's session information is stored in the cookie. If the client completely disables the cookie function, it cannot enjoy the function provided by the session.

In view of the above defects of ASP session, Microsoft designers are designing and developing ASP. net session, and the above defects are completely overcome, making ASP. net session has become a more powerful feature.

Introduction to the Web. config file

Some ASP. NET programmers say: What is the Web. config file? I have never heard of it, but can the program I wrote work properly? Yes, you are right. Without the Web. config file program, it can run normally. However, if you create a large website, you need to make some overall configuration for the entire website, for example, you need to use the web. config file. Although some options in the web. config file can be configured through IIS, if the corresponding settings in Web. config also overwrite the configuration in IIS. In addition, the biggest convenience of the web. config file is that you can access the settings in Web. config by calling the system. Web namespace on the ASP. NET page.

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.