ASP.NET session time setting

巴扎黑
Release: 2016-12-20 15:51:09
Original
1645 people have browsed it

ASP.NET session time setting
Method 1:

The default time setting of asp.net Session is 20 minutes, that is, after 20 minutes, the server will automatically give up the session information.
When we open webconfig in the asp.net program , you can see the following code:
Asp.net program code:
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1 ;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
The above code is to configure how the application stores Session information.
The timeout="20" is asp. net session default time. If you need to change the time, just fill in a different value here. The default unit is minutes.


sessionState node attribute:

cookieless="true|false"
timeout="number of minutes"
stateConnectionString="tcpip=server:port"
sqlConnectionString="sql connection string"
stateNetworkTimeout="number of seconds"
/>

Must have The attributes are

mode to set where the Session information is stored
Off is set to not use the Session function
InProc is set to store the Session in the process, which is the storage method in ASP, this is the default value.
StateServer is set up to store Session in a separate state service.
SQLServer Sets the Session to be stored in SQL Server

The optional attributes are:
cookieless Sets where the client’s Session information is stored
ture Uses Cookieless mode
false Uses Cookie mode, which is the default value.
timeout sets the number of minutes after which the server automatically gives up session information. The default is 20 minutes
stateConnectionString sets the server name and port number used when Session information is stored in the state service, for example: "tcpip=127.0.0.1:42424". This attribute is required when the value of mode is StateServer.
sqlConnectionString Sets the connection string when connecting to SQL Server. This attribute is required when the value of mode is SQLServer.
stateNetworkTimeout sets the number of idle seconds after which the TCP/IP connection between the Web server and the server storing the status information is disconnected when using the StateServer mode to store the Session state. The default value is 10 seconds

How to set the ASP.NET session time 2: However, sometimes modifying the configuration file cannot solve this problem well.

You can modify it in Global.asax in the public program. After we find Session_Start in global.asax, we can set it as follows.

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session starts
Session.Timeout = 600;
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!