ASP. NET session usage and principles

Source: Internet
Author: User
Import read: in ASP. NET, the session can work without Cookie.
This article Article This article introduces its mechanism and explains this principle, which will be of great help to the use of sessions.
--------------------------------------------------------------------------------
Session management, our traditional ASP Program It 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 is displayed indicating whether to allow cookies. When we set it to not allow cookies, our session will always fail. for example:

<%
Session ("username") = "fan weixiao"
Session ("url") = http://www.onlyvc.org
%>

In ASP. NET environment, the session is completely re-defined, 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 are unwilling to study it, tofu said: in fact, the use of Asp.net is the same as that of ASP, or even simpler, because according to the observation of bean curd, we do not need to continue to consider the status of the cookie option on the client, because the session can be smoothly transmitted regardless of the client settings.

Next we will give a brief and in-depth understanding of the Asp.net session mechanism. Due to the limited technology, I am not very clear about some 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 both inproc and usesqlserver are false, an out process mechanism is adopted to store sessions on a server dedicated to storing sessions. This allows 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") = "fan weixiao" %>
<% = SESSION ("name") %>
After the program is executed, we do not receive any prompts from the browser, although we also use the session
When we set cookieless to true and run this program again, we find that the program is still
Correct execution, but the address bar of the browser has changed. We used
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.
So I can't do anything about this part of SQL server. If I'm not happy with it, I installed a PDC version. Now I regret it :(

Through these studies, do we have a better understanding of the Asp.net session mechanism?

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.