1,Forms身份验证:

  

验证方法

我们可以使用下面 4 种方法中的一种进行票证写入和重定向操作,其实前 3 种只不过是对第 4 种方法的封装而已。推荐使用 1、4。注意后三种方法不支持cookieless="UseUri"。

// 1. 使用缺省身份验证票证
FormsAuthentication.RedirectFromLoginPage("username", true);
// 2. 使用缺省身份验证票证
FormsAuthentication.SetAuthCookie("username", false);Response.Redirect(FormsAuthentication.GetRedirectUrl("username", false));
// 3. 使用缺省身份验证票证
Response.Cookies.Add(FormsAuthentication.GetAuthCookie("username", false));
Response.Redirect(FormsAuthentication.GetRedirectUrl("username", false));
// 4. 使用自定义身份验证票证
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "username", DateTime.Now, DateTime.Now.AddMinutes(10), false, null);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)));
Response.Redirect(FormsAuthentication.GetRedirectUrl("username", false));

相关文章:

  • 2021-05-29
  • 2022-01-08
  • 2022-12-23
  • 2021-11-25
  • 2021-08-19
  • 2021-11-19
猜你喜欢
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案