The experience of one of the methods that does not lose session

Source: Internet
Author: User
Tags config configuration settings iis net
Session

Session loss is a familiar problem, in their own also understand some how to solve the problem, but there has been no opportunity to use, now because of new projects to be developed under B/s, so I have to consider the session of the problem.

There are two ways to resolve session loss: 1 Save session in a sate server. 2 Saves the session in SQL Server. We use the database is Oracle, do not want to install a database, so use the first method.

First, according to the information on the Internet to the Webconfig file in the session part of the modification. As follows:

<sessionstate
Mode= "StateServer"
Cookieless= "false"
timeout= "240"
Stateconnectionstring= "tcpip=10.164.222.122:42424"
statenetworktimeout= "14400"
/>
<machinekey
validationkey= "78ae3850338bfadce59d8ddf58c9e4518e7510149c46142d7aad7f1ad49d95d4"
decryptionkey= "5fc88dfc24ea123c"
validation= "SHA1"
/>

And then the ASP.net State Server service starts on the 10.164.222.122 computer.

That's basically what it's all about. Experience.

I used a test program that was still available after 3 hours, even more so that my computer was reset and the session was still available on the pages that were open on other computers. After some experience, it feels really good.

. NET Framework General Reference

<sessionState> elements
Configures session state settings for the current application.

<configuration>
<system.web>
<sessionState>

<sessionstate mode= "off| inproc| stateserver| SQL Server "
Cookieless= "True|false"
timeout= "Number of minutes"
Stateconnectionstring= "Tcpip=server:port"
sqlconnectionstring= "SQL connection string"
statenetworktimeout= "Number of seconds"/>
Required Attributes
Attribute Options Description
mode specifies where session state is stored.
Off indicates that session state is not enabled.
InProc indicates that session state is stored locally.
StateServer indicates that session state is stored on a remote computer.
SQL Server indicates that the session state is stored on SQL Servers.

Optional properties
Attribute Options Description
cookieless specifies whether a session that does not have a Cookie should be used to identify the client session.
True indicates that a session with no cookies should be used.
False indicates that a session without cookies should not be used. The default value is False.
Timeout Specifies the number of minutes that the session can be idle before a session is discarded. The default value is 20.
stateconnectionstring Specifies the server name and port for Remote Storage session state. For example, "tcpip=127.0.0.1:42424". This property is required when mode is StateServer.
sqlConnectionString Specifies the connection string for SQL Server. For example, "Data source=localhost;integrated security=sspi;initial catalog=northwind". This property is required when mode is SQL Server.
STATENETWORKTIMEOUT specifies the time, in seconds, between the TCP/IP network connection between the WEB server and the state server before the session is discarded, when the session state is stored in the StateServer mode. The default value is 10.

Note
Using StateServer mode

Make sure that the server running the ASP.net state service is a remote server to store session-state information. This service is installed with ASP.net, and its default location is < drive >:\systemroot\microsoft.net\framework\version\aspnet_state.exe.
In the application's Web.config file, set the Mode=stateserver and set the stateConnectionString property. For example, stateconnectionstring= "tcpip=sarath:42424".
Using SQL Server Mode

Run InstallSqlState.sql on the computer that is running SQL Server (it will store session state) (the default installation location is < drive >:\systemroot\microsoft.net\framework\ Version). This creates a database named ASPState that has a new stored procedure and has aspstatetempapplications tables and aspstatetempsessions tables in the TempDB database.
In the application's Web.config file, set the Mode=sqlserver and set the sqlConnectionString property. For example, sqlconnectionstring= "Data source=localhost;integrated security=sspi;initial catalog=northwind".
Example
The following example specifies several session-state configuration settings.

<configuration>
<system.web>
<sessionstate mode= "InProc"
Cookieless= "true"
Timeout= "/>"
</sessionState>
</system.web>
</configuration>
Requirements
Included in:<system.web>

WEB Platform: IIS 5.0, IIS 5.1, IIS 6.0

Configuration files: Machine.config, web.config

Configuration section Handler: System.Web.SessionState.SessionStateSectionHandler

Please see
asp.net configuration | asp.net Settings Schema | SessionStateModule



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.