ASP.NET 身份验证票

using System.Web.Security;

1.创建验证票据

               //1) 创建一个验证票据
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Account.Text, DateTime.Now,  DateTime.Now.AddMinutes(30), false, Account.Text);
                //2) 并且加密票据
                string cookieStr = FormsAuthentication.Encrypt(ticket);
                //3) 创建cookie
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieStr);
                //cookie存放路径
                cookie.Path = FormsAuthentication.FormsCookiePath;
                Response.Cookies.Add(cookie); 

2.读取验证票中的数据

    string account ="";
    HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
    if (cookie != null)
    {
         string cookieStr = cookie.Value;
         FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookieStr);
         account = ticket.UserData.ToString();
    }

阅读更多
想对作者说点什么? 我来说一句

asp.net身份验证票源码

2010年01月13日 21KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭