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");
}
}