【发布时间】:2011-01-02 11:32:48
【问题描述】:
我有一个测试项目,web.config 中指定的表单超时超过了我在 FormsAuthenticationTicket 中设置的超时。根据文档,FormsAuthenticationTicket 中的超时(过期日期)必须覆盖 web.config 中的超时。
文档位于:http://support.microsoft.com/kb/910443
If the ticket is generated manually by using the FormsAuthenticationTicket class, the time-out can be set through the Expiration attribute. This value will override the timeout attribute value specified in configuration files.
这是我的代码:
Web.config:
<authentication mode="Forms">
<forms
timeout="1"
loginUrl="login.aspx"
name="sessionTest"
cookieless="UseCookies"
defaultUrl="default.aspx"
/>
</authentication>
登录.aspc.cs:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(Login1.UserName, false, 2);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(cookie);
// redirect user
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
现在,当我登录时,我在 1 分钟不活动后被重定向。这不应该发生,对吧?我必须在 2 分钟后被重定向。
谁能解释一下?
【问题讨论】:
标签: c# asp.net forms-authentication