C# 在 asp.net mvc 中更改会话变量超时的默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17741775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the default value of session's variable timeout in asp.net mvc
提问by Lamloumi Afif
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
.
我有一个带有 razor 视图引擎的 Asp.net Mvc 应用程序,我在其中使用了一个变量Session['user']
:当用户登录应用程序Session['user'] = login
和注销时,此变量作为值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.
问题是有一个短暂的超时并且会话变量过期:如果我在Session['user'] =null
自动登录应用程序后一分钟内什么都不做。
So how can i set the timeout of the session's variable unlimited until it is changed by program?Any suggestions?
那么如何将会话变量的超时设置为无限制,直到它被程序更改?有什么建议吗?
采纳答案by Arun Chandran C
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.
您不能将timeout
值设置为无限制。
You can increase the time out value in minutes using the timeout
attribute of sessionState
element in web.config.
您可以使用web.config 中timeout
的sessionState
element属性以分钟为单位增加超时值。
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)
默认情况下,ASP.NET 使用 cookie 来标识哪些请求属于特定会话。如果 cookie 不可用,则可以通过向 URL 添加会话标识符来跟踪会话。要禁用 cookie,请设置sessionState cookieless="true".
(120 = 分钟)
<sessionState mode="StateServer" cookieless="false" timeout="120"/>
Check out this Session-Time out
看看这个会话超时
回答by ssilas777
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
您不能将其分配给无限制。您可以使用会话状态元素的超时属性以分钟为单位增加值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
默认会话超时值为 20 分钟。同样在您的情况下,如果您使用表单身份验证,请检查身份验证超时值
<authentication mode="Forms">
<forms loginUrl="logon.aspx"
protection="All" path="/" timeout="30" />
</authentication>
回答by Anuradha Kulkarni
It's timeout of the session, not the variable. Set it in configuration in minutes
这是会话超时,而不是变量。在几分钟内将其设置为配置
<sessionState timeout="30" />
回答by Minal Raniga
It is not possible to set the session time out to unlimited.
Instead set the session time out to a high value.
Example:
无法将会话超时设置为无限制。
而是将会话超时设置为高值。
例子:
<configuration>
<system.web>
<sessionState mode="InProc" timeout="350" />
</system.web>
</configuration>
回答by Momodu Deen Swarray
I had a similar problem earlier and it was not about the Session Timeout value. Hence, Sometimes its now about the Timeout period. This Session Timeout may be set to 20 mins or more but if the hosting server or your computer is VERY LOWon MEMORY. The Session values are then cleared and the user will have to sometimes login again.
我之前遇到过类似的问题,这与会话超时值无关。因此,有时它现在是超时期限。该会话超时可以设置为20分钟或以上,但如果托管服务器或您的计算机是非常低的内存。然后清除会话值,用户有时必须再次登录。
This low memory is sometimes caused by STORING IMAGESor BINARY VALUESin the Database instead of storing as Files on the Server and access them using System.IO.File procedure. So when you attempt to fetch some records, their IMAGES DATA on the TABLE will also be fetched, resulting in a SIGNIFICANT reduction in performance and also OVER-CONSUMPTION of available MEMORY.
这种低内存有时是由在数据库中存储图像或二进制值而不是作为文件存储在服务器上并使用 System.IO.File 过程访问它们造成的。因此,当您尝试获取某些记录时,它们在 TABLE 上的图像数据也将被获取,从而导致性能显着降低以及可用内存的过度消耗。
IT MAY BE THAT YOUR COMPUTER OR HOSTING IS VERY LOW ON MEMORY(Not Storage Space)
可能是您的计算机或主机内存不足(不是存储空间)
Hope this helps.
希望这可以帮助。