您的位置:首页 > 编程语言 > ASP

asp.net 身份验证 写入cookie 失效日期

2013-04-02 10:57 232 查看
protected void Page_Load(object sender, EventArgs e)

{

FormsAuthentication.Initialize();

string loginName = Server.HtmlEncode(Request.Form["txtUserName"]);

string password = Server.HtmlEncode(Request.Form["txtPassword"]);

if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password))

return;

IUserBLL userBll = ObjectBuilder.Create<IUserBLL>();

if (userBll.Login(loginName, password))

{

// 创建一个authentication ticket ,把用户名和roles保存到该ticket中

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(

1,

loginName,

DateTime.Now,

DateTime.Now.AddMinutes(300),

true,

"",

FormsAuthentication.FormsCookiePath);

//加密

string encTicket = FormsAuthentication.Encrypt(ticket);

HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);

Response.Cookies.Add(cookie);

Response.Redirect("Frame/Default.aspx");

}

else

{

Response.Redirect("../Default.htm?msg=errorinput");

//Response.Redirect("Login.aspx?msg=errorinput");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: