Asp.net configures Session Status Session implementation code

Source: Internet
Author: User

The following is a detailed description:

Copy codeThe Code is as follows: <sessionState
Timeout = "timeout in minutes"
Cookieless = "[true | false]"
Mode = "Off | InProc | StateServer | SQLServer"
StateConnectionString = "tcpip = server: port"
StateNetworkTimeout = "for network operations with State Server, in seconds"
SqlConnectionString = "valid SqlConnection string, minus Initial Catalog"
/>

Timeout: Specifies the lifetime of the session after the activity ends (in minutes ). If a user is not activated for a specified period of time, a new session will be created, and all previous statuses will be lost.
Cookieless: by default, the generated session ID is stored in a cookie. Later, the cookie will be ASP in other requests. to determine the session Status and connect to the current user.
If some users disable cookies in the browser, we can use cookieless to enable session status for these users. When it is set to true, ASP. NET automatically appends the session ID to the URL and any related URLs that exist on the requested page.

Disabled, set to false
Enabled, set to true

This mechanism adds a processing step, because all links on the page must be overwritten to include the session ID, the requested URL must be parsed before it can be extracted and the actual resource URL (no session ID) can be obtained ).
Mode: Status mode.

InProc -- this is a default setting. All statuses are stored in the memory of the same process running the application. This can optimize the performance, but if the application is restarted or the process is suspended for some reason, all session data of the relevant user will be lost.

StateServer -- this setting can be used to detach state memory from processes running the application. It can combine the following two attributes:
StateConnectionString = "tcpip = server: port" stateNetworkTimeout = "for network operations with State Server, in seconds"

You can save the status information to its own processes and memory by specifying the address and port of the machine. In this way, the status can be isolated from the application to prevent failure. In the status server and the ASP. NET status service must be started. The service can be started either through the Serivces console or through the following command prompt:

> Net start aspnet_state

You can also set this service to automatically start. By setting the IP address of the Status server, you can specify the corresponding machine to save the status information of the application. This prevents the application server from restarting, but does not prevent the machine from restarting. It should also be noted that placing the state memory outside the application process may cause performance conflicts, especially when the application is located on another machine in the network. Check whether the conflict caused by retaining session information is normal.

SQLServer -- if you decide to retain the session status at any cost, you can use this setting. This mode stores all session statuses in the SQL Server database, so it can withstand any failed operations of applications, servers, and even database servers (assuming the database itself is not faulty. Setting this mode is to configure the following attributes of the sessionState element:

SqlConnectionString = "valid SqlConnection string, minus Initial Catalog"
You must also run a script to prepare the database for storing the status. The installsqlstate. SQL file in the path D: \ WINDOWS \ Microsoft. NET \ Framework \ v1.1.4322

You do not need to use SQL Server 2000 Query Analyzer (Query Analyzer) to run this script ). MSDE provides us with a command line utility: osql.
> Osql-S [servername]-U [login]-P [pwd] <InstallSqlState. SQL
To achieve maximum reliability, we can even group SQL Server. This mode is the most effective way to protect the session state, but in terms of performance, this mode is also the most expensive. Each request needs to be round-trips between databases, which seriously affects application response. At the same time, the use of the network for processing will also cause bottlenecks due to high load.

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.