会话变量在asp.net应用程序超时 [英] session variables timeout in asp.net app
问题描述
在我的web应用程序,我使用了一些会话变量,这是当我登录设置:
例如。 会议(USER_ID)=读卡器(user_ID的)
我使用这个通过我的应用程序。
在会话变量超时,这个连接到数据库会议(user_ID的)
需要一些查询。
我如何设置我的会话变量,这样一旦被超时去到登录页面或至少是如何增加的时间长度有哪些?
我猜你使用表单验证。这里的关键是要确保会话不会在你的窗体身份验证过期。
我在这个答案写到这里这个
<一个href=\"http://stackoverflow.com/questions/654005/how-to-redirect-to-login-page-when-session-is-expired-asp-net-3-5-formsauthen/654297#654297\">How重定向到登录页面时,会议已过期(ASP.NET 3.5 FormsAuthen)
块引用>例如:
配置您的表单验证 - 这将超时时间设置为60分钟:
&LT;身份验证模式=表格&GT;
&LT;形式defaultUrl =〜/ Default.aspx的
loginUrl =〜/的Login.aspx
slidingExpiration =真
超时=60/&GT;
&LT; /认证&GT;扩展会话到期时间较长:
&LT;的sessionState
模式=是InProc
无Cookie =假
超时=70/&GT;在你的
的Login.aspx
code的背后,你也可以做一个Session.Clear();
分配会话值之前删除过时的会话数据。In my web app I'm using some session variables, which are set when I login:
e.g.
Session("user_id") = reader("user_id")
I use this through my app.
When the session variable times out, this throws errors mainly when connecting to the database as
session("user_id")
is required for some queries.How can I set my session variables so that once they are timed out to go to the login page or how can at least increase the length of time the are available?
解决方案I'm guessing you're using Forms Authentication. The trick here is to ensure that your Forms Authentication expires before the session does.
I wrote about this in this answer here:
How to redirect to LogIn page when Session is expired (ASP.NET 3.5 FormsAuthen)
For example:
Configure your Forms Authentication - this sets the timeout to 60 minutes:
<authentication mode="Forms"> <forms defaultUrl="~/Default.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="60" /> </authentication>
Extend Session expiry to a longer time:
<sessionState mode="InProc" cookieless="false" timeout="70"/>
In your
Login.aspx
code behind you could also do aSession.Clear();
to remove stale session data before assigning session values.这篇关于会话变量在asp.net应用程序超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!