【问题标题】:asp.net Remember Me System with FormsAuthenticationTicket带有 FormsAuthenticationTicket 的 asp.net 记住我系统
【发布时间】:2023-03-20 10:35:02
【问题描述】:

我正在尝试在 asp.net 项目上做记住我的系统。我做了用户注册和登录 FormsAuthenticationTicket。我想要的是当用户登录时,我按预期设置了一个持久性 cookie,我验证我可以添加 cookie 但 FormsAuthenticationTicket 不处理记忆的事情。这是我的代码

ticket = new FormsAuthenticationTicket(1,
                                            (String)(drUserInfo["Email"]),
                                            DateTime.Now,
                                            DateTime.Now.AddMinutes(30),
                                            Login1.RememberMeSet,
                                            (String)(drUserInfo["UserType"]));
                encryptedStr = FormsAuthentication.Encrypt(ticket);

你能帮我解决这个问题吗? FormsAuthenticationTicket 是否处理记住我系统或我?

【问题讨论】:

  • FormsAuthentication 处理它。 asp:Login 控件中有一个复选框,用于设置加密的 cookie
  • 您可能想使用 ILSpy 并检查 asp 中发生的情况:登录控件代码
  • 我看到登录控制创建了一个加密的cookie。但还是不行
  • 从 asp 开始:登录源代码我看到他们使用我的答案中的代码设置了 cookie(现在就写吧

标签: asp.net formsauthenticationticket


【解决方案1】:

查看 asp:Login 的源代码,我看到 cookie 是通过以下调用获得的:

从 System.Web.UI.WebControls.Login.AttemptLogin 调用

if (authenticateEventArgs.Authenticated)
{
    FormsAuthentication.SetAuthCookie(this.UserNameInternal, this.RememberMeSet);
    this.OnLoggedIn(EventArgs.Empty);
    this.Page.Response.Redirect(this.GetRedirectUrl(), false);
    return;
}

FormsAuthentication.SetAuthCookie(this.UserNameInternal, this.RememberMeSet); 是电话

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 2011-01-28
    • 2011-03-22
    • 2017-06-04
    • 2011-03-08
    • 1970-01-01
    相关资源
    最近更新 更多