日期:2014-05-16 浏览次数:20531 次
string username = Request["username"].ToString();
string password = Request["password"].ToString();
//验证数据库用户表
UserModel user = DllFactory.getTrainDll.getUser(username, password);
if (user != null)//通过
{
HttpCookie aspCookies = new HttpCookie("aspusername");
HttpCookie aspCookiesPwd = new HttpCookie("password");
HttpCookie aspCookiesuid = new HttpCookie("uid");
HttpCookie aspCookiesPower = new HttpCookie("spower");//T代表教师,U代表学生,S代表管理员
HttpCookie aspCookiesUserID = new HttpCookie("aspuserId");
aspCookies.Value = Server.UrlEncode(user.UserName.ToString());
aspCookiesPwd.Value = user.PassWord;
aspCookiesuid.Value = user.Uid.ToString();
aspCookiesPower.Value = user.Spower.ToString();
aspCookiesUserID.Value = user.Uid2;
aspCookies.Expires = DateTime.Now.AddDays(3);
aspCookiesPwd.Expires = DateTime.Now.AddDays(3);
aspCookiesuid.Expires = DateTime.Now.AddDays(3);
aspCookiesPower.Expires = DateTime.Now.AddDays(3);
aspCookiesUserID.Expires = DateTime.Now.AddDays(3);
HttpContext.Current.Response.Cookies.Add(aspCookies);
HttpContext.Current.Response.Cookies.Add(aspCookiesuid);
HttpContext.Current.Response.Cookies.Add(aspCookiesPwd);
HttpContext.Current.Response.Cookies.Add(aspCookiesPower);
HttpContext.Current.Response.Cookies.Add(aspCookiesUserID);
Response.Redirect("index.aspx");
}
HttpCookie cookies = Request.Cookies["aspusername"];
if (cookies != null)
{
cookies.Expires = System.DateTime.Now.AddDays(-30);
Response.Cookies.Add(cookies);
}
HttpCookie cookies1 = Request.Cookies["password"];
if (cookies1 != null)
{
cookies1.Expires = System.DateTime.Now.AddDays(-30);
Response.Cookies.Add(cookies1);
}
HttpCookie cookies2 = Request.Cookies["uid"];
if (cookies2 != null)
{
cookies2.Expires = System.DateTime.Now.AddDays(-30);
Response.Cookies.Add(cookies2);
}
HttpCookie cookies3 = Request.Cookies["spower"];
if (cookies3 != null)
{
cookies3.Expires = System.DateTime.Now.AddDays(-30);
Response.Cookies.Add(cookies3);
}
HttpCookie cookies4 = Request.Cookies["aspuserId"];
if (cookies4 != null)
{
cookies4.Expires = System.DateTime.Now.AddDays(-30);
Response.Cookies.Add(cookies4);
}