【问题标题】:C# Formsauthentication timeout in web.config overrules manual ticket timeout?web.config 中的 C# Formsauthentication 超时会否决手动票证超时?
【发布时间】: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


    【解决方案1】:

    我认为对 RedirectFromLoginPage 的调用正在覆盖您的 cookie。您可以尝试改用它。

    Response.Redirect( FormsAuthentication.GetRedirectUrl( UserName.Text, chkPersistCookie.Checked );
    

    此处可能有用的其他信息:http://www.4guysfromrolla.com/webtech/110701-1.3.shtml

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      相关资源
      最近更新 更多