zoukankan      html  css  js  c++  java
  • 票证

    //登录认证
    public void LoginAuthentication(string UserName, string passWord, string rememberPassowrd)
    {
    string userData = rememberPassowrd + "|" + passWord;
    System.Web.Security.FormsAuthenticationTicket tk = new System.Web.Security.FormsAuthenticationTicket(
    1, //指定版本号:可随意指定
    UserName,
    System.DateTime.Now, //发布时间
    System.DateTime.Now.AddDays(7), //失效时间
    false, //是否为持久 Cookie:尚未发现有何用,至少目前偶还不知,下面会有说明
    userData//用户数据:可用 ((System.Web.Security.FormsIdentity)User.Identity).Ticket.UserData 获取
    );
    string str = System.Web.Security.FormsAuthentication.Encrypt(tk);//加密身份验票

    //声明一个 Cookie,名称为 Web.config 中 <forms name=".APSX" … /> 的 name 属性,对应的值为身份验票加密后的字串
    System.Web.HttpCookie ck = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, str);

    //指定 Cookie 为 Web.config 中 <forms path="/" … /> path 属性,不指定则默认为“/”
    ck.Path = System.Web.Security.FormsAuthentication.FormsCookiePath;
    //此句非常重要,少了的话,就算此 Cookie 在身份验票中指定为持久性 Cookie ,也只是即时型的 Cookie 关闭浏览器后就失效;因此上面我说:我是真的还不知在身份验票中指定为持久性 Cookie 有何用。
    if (rememberPassowrd.ToLower() == "true")
    {
    ck.Expires = System.DateTime.Now.AddDays(7);
    }

    Response.Cookies.Add(ck);//添加至客房端
    }

  • 相关阅读:
    [网络] 第五章 运输层
    pubwin
    R语言
    我的微博开通啦
    迅雷使用积分制的真正作用和目的 [揭密迅雷]
    求数组里面第二大的数
    xp环境下安装vmware workstation 7出错
    一道大学c语言作业题
    写在断网的那些日子里
    mysql里奇怪的日期201627 14:28:15
  • 原文地址:https://www.cnblogs.com/zhangweixin/p/5340227.html
Copyright © 2011-2022 走看看