身份验证票据生成

if (FormsAuthentication.Authenticate(UserName.Value,      UserPassword.Value))

  {

      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (UserName.Value, false, 5000);

      //将经过身份验证的用户重定向回最初请求的 URL 或默认 URL。第一参数:经过验证的用户名 第二个参数若要创建持久 Cookie(跨浏览器会话保存的 Cookie),则为 true;否则为 false

      FormsAuthentication.RedirectFromLoginPage(UserName.Value,Persist.Checked);

  }

 

 

  if (Membership.ValidateUser(username, password))

  {

      string userData = "ApplicationSpecific data for this user.";

 

      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,

        username,

        DateTime.Now,

        DateTime.Now.AddMinutes(30),

        isPersistent,

        userData,

        FormsAuthentication.FormsCookiePath);

 

      // Encrypt the ticket.

      string encTicket = FormsAuthentication.Encrypt(ticket);

 

      // Create the cookie.

      Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

 

      // 返回导致重定向到登录页的原始请求的重定向 URL

      Response.Redirect(FormsAuthentication.GetRedirectUrl(username, isPersistent));

  }

 

 

FormsAuthentication.SetAuthCookie (String, Boolean, String) 方法为提供的用户名创建一个身份验证票证,并使用提供的 Cookie 路径或 URL 将其添加到响应的 Cookie 集合。参数1: 已验证的用户的名称。参数2: 若要创建持久 Cookie(跨浏览器会话保存的 Cookie),则为 true;否则为 false。参数3: Forms 身份验证票证的 Cookie 路径。

public static void SetAuthCookie(string userName,bool createPersistentCookie,  string strCookiePath)

FormsAuthenticationGetAuthCookie 方法 (String, Boolean, String) 为给定的用户名创建身份验证 Cookie。返回一个 HttpCookie,其中包含加密的 Forms 身份验证票证信息。

public static HttpCookie GetAuthCookie(string userName,bool createPersistentCookie,string strCookiePath)

 

FormsAuthentication..::.FormsCookieName 属性获取用于存储 Forms 身份验证票证的 Cookie 名称。用于存储 Forms 身份验证票证的 Cookie 名称。默认值是.ASPXAUTH

FormsCookieName 属性值是在 ASP.NET 应用程序的配置文件中使用 forms 配置元素的 name 属性设置的。FormsCookieName 用于引用存储 FormsAuthenticationTicket 信息的 Cookie

 

FormsAuthenticationTicket 提供对票证的属性和值的访问,这些票证用于 Forms 身份验证对用户进行标识。无法继承。

 public FormsAuthenticationTicket(int version, string name, DateTime issueDate, DateTime expiration,   bool isPersistent,     string userData,   string cookiePath) version:票证的版本号。name:与票证关联的用户名。issueDate:票证发出时的本地日期和时间。expiration:票证过期时的本地日期和时间。isPersistent:如果票证将存储在持久性 Cookie 中(跨浏览器会话保存),则为 true;否则为 false。如果该票证存储在 URL 中,将忽略此值。userData:存储在票证中的用户特定的数据。cookiePath:票证存储在 Cookie 中时的路径。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值