日期:2014-05-16  浏览次数:20531 次

一个异常问题(登陆cookie)
客户那边是虚拟机,web登录是用cookie做的,现在出现了一个异常问题,客户端有时候出现无法登陆,检测到cookie是不存在的,重新登陆无反应。但是在服务器内登陆却是正常。这个异常要重启服务器才能恢复正常。
搞不懂什么异常?????????

登陆代码

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