票证

//登录认证
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);//添加至客房端
}

转载于:https://www.cnblogs.com/zhangweixin/p/5340227.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值