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");
}
}
{
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");
}
}
相关文章推荐
- ASP.NET在IE9,IE10,IE11中Form表单身份验证失效问题解决方法
- 使用 Cookie 而无需 ASP.NET 核心标识的身份验证
- 采用Asp.Net的Forms身份验证时,非持久Cookie的过期时间会自动扩展
- ASP.NET MVC Cookie 身份验证
- ASP.NET Core 使用Cookie验证身份
- Asp.Net的Forms验证,解决Cookie和Seesion失效时间。
- ASP.NET在IE10中Form表单身份验证失效问题解决方法
- ASP.NET在IE10,IE11中Form表单身份验证失效问题解决方法
- [原创]采用Asp.Net的Forms身份验证时,持久Cookie的过期时间会自动扩展
- [原创]采用Asp.Net的Forms身份验证时,持久Cookie的过期时间会自动扩展
- ASP.NET如何实现服务器端身份验证和客户端状态管理?(Session机制和Cookie)
- asp.net 解决IE11下 From身份验证失效问题
- 采用Asp.Net的Forms身份验证时,持久Cookie的过期时间会自动扩展
- Asp.Net的Forms验证,解决Cookie和Seesion失效时间
- ASP.NET Core 使用Cookie验证身份
- ASP.NET在IE9,IE10,IE11中Form表单身份验证失效问题解决方法
- ASP.NET Core 使用Cookie验证身份
- ASP.NET Core 使用Cookie验证身份
- 采用Asp.Net的Forms身份验证时,持久Cookie的过期时间会自动扩展
- Asp.Net的Forms验证,解决Cookie和Seesion失效时间