zoukankan      html  css  js  c++  java
  • web版本的用户登陆票据 FormsAuthenticationTicket

    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "username", DateTime.Now, DateTime.Now.AddDays(365),
    true, string.Format("{0}:{1}", "username", "password"), FormsAuthentication.FormsCookiePath);
    //这边的 string.Format("{0}:{1}", "username", "password"),也可以改为任何值,如密码或IP
    string ticString = FormsAuthentication.Encrypt(ticket);
    //将加密后的票据保存为cookie
    HttpCookie coo = new HttpCookie(FormsAuthentication.FormsCookieName, ticString);
    //这里的IsPersistent不会自己判断,需要手工判断,但FormsAuthenticationTicket的expiration的值是有过期性的,无论cookie的Expires设置多久,只要expiration到期,即使cookie存在用户验证也将失败
    if (ticket.IsPersistent)
    {
    coo.Expires = ticket.Expiration;
    }
    //使用加入了userdata的新cookie
    Response.Cookies.Add(coo);
    //FormsAuthentication.SetAuthCookie("username", true);//这种是快速写法,用了这种写法就可以不用自己建ticket票据,也无法使用UserData等参数了


    //FormsAuthentication.SignOut//用来清除这个Cookie标记//FormsAuthentication.RedirectFromLoginPage(userID, createPersistentCookie);

    // <authentication mode="Forms">
    // <forms name=".MyCookie" loginUrl="Login.aspx" protection="All" timeout="60"/>
    // </authentication>

  • 相关阅读:
    列表 元组
    前端 3
    前端 2
    python pymysql 表和数据的备份
    python 树 索引
    python 数据库连表查询习题
    python 数据库表查询
    python 数据库usdr 查询
    python set enum 完整性约束
    python 数据库表操作
  • 原文地址:https://www.cnblogs.com/zhuqun/p/12035020.html
Copyright © 2011-2022 走看看