Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the default value of session's variable timeout in asp.net mvc

I have an Asp.net Mvc application with razor views engine , in which i used a variable Session['user'] : when an user log on the application Session['user'] = login and in the logout this variable takes as value Null.

The problem is that there is a short timeout and the session variable expires : if i do nothing in one minute after log on the application Session['user'] =null automatically.

So how can i set the timeout of the session's variable unlimited until it is changed by program?Any suggestions?

like image 841
Lamloumi Afif Avatar asked Jul 19 '13 08:07

Lamloumi Afif


People also ask

How can change session timeout in ASP NET MVC?

Open the web. config file, then increase the value in minutes by using the time out attribute of SessionState element. By default, the session timeout value is 20 minutes. Also in your case if you are using forms authentication, please check the timeout value.

What is the default session timeout in MVC?

The default is 20 minutes.

What is the default session timeout in asp net c#?

The default is 10 minutes.

How do you set the value of a session timeout property?

The Timeout property can be set in the Web. config file for an application using the timeout attribute of the sessionState configuration element, or you can set the Timeout property value directly using application code. The Timeout property cannot be set to a value greater than 525,600 minutes (1 year).


2 Answers

So how can i set the timeout of the session's variable unlimited until it is changed by program?Any suggestions?

You can't set timeout value to unlimited.

You can increase the time out value in minutes using the timeout attribute of sessionState element in web.config.


SESSION STATE SETTINGS

By default ASP.NET uses cookies to identify which requests belong to a particular session. If cookies are not available, a session can be tracked by adding a session identifier to the URL. To disable cookies, set sessionState cookieless="true". (120 = minutes)

<sessionState mode="StateServer" cookieless="false" timeout="120"/>

Check out this Session-Time out

like image 95
Arun Chandran C Avatar answered Sep 30 '22 07:09

Arun Chandran C


You cannot assign it to unlimited. You can increase the value in minutes using the time out attribute of Session state element in web.config

<sessionState timeout="30">
</sessionState>

By default session timeout value is 20 minutes. Also in your case if you are using forms authentication, check the authentication time out value as well

<authentication mode="Forms">
   <forms loginUrl="logon.aspx" 
   protection="All" path="/" timeout="30" />
</authentication>  
like image 43
ssilas777 Avatar answered Sep 30 '22 07:09

ssilas777