Session在IE中不起作用,它适用于所有其他浏览器

时间:2013-06-09 06:29:46

标签: asp.net session generic-handler

我正在使用asp.net,visual studio 2012,IIS8,.Net Framework 4开发一个网站。

登录后我使用SESSIONS存储用户信息。

当用户点击登录按钮时,我将信息发送到.ashx文件,如下所示:

 var url = "SignIn.ashx?username=" + UserName.value + "&password=" + PassWord.value;
 xmlRequest_SignIn.open("GET", url);
 xmlRequest_SignIn.onreadystatechange = function () { ApplyUpdateSignIn() }
 xmlRequest_SignIn.send(null);

SignIn.ashx:

  ... // check login information and then
  HttpContext.Current.Session["UserName"] = username.toString();
  ...

现在在我网站的每个页面中,我都会检查此会话以在ajax中验证用户:

var url = "CheckMemberAccount.ashx";
xmlRequest_member.open("GET", url);
xmlRequest_member.onreadystatechange = function () { ApplyUpdateGetMemberAccount() }
xmlRequest_member.send(null);

CheckMemberAccount.ashx:

if (Convert.ToString(HttpContext.Current.Session["UserName"]) == "" || null == HttpContext.Current.Session["UserName"])
{
    // user not logged in
}
else
{
    // user logged in
} 

对于注销我也使用ajax:

  var url = "SignOut.ashx";
  xmlRequest_SignOut.open(GET, url);
  xmlRequest_SignOut.onreadystatechange = function () { ApplyUpdateSignOut() }
  xmlRequest_SignOut.send(null);

SignOut.ashx:

 // I try everything to make the session null or invalid!
 // BUT it doesn't take effect in Internet Explorer !!
 HttpContext.Current.Session["UserName"] = "";
 HttpContext.Current.Session["UserName"] = null;
 HttpContext.Current.Session.Clear();
 HttpContext.Current.Session.RemoveAll();
 HttpContext.Current.Session.Abandon();
 HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value = "";

正如你所看到的,我已经尝试了使会话无效或无效的所有内容。 此代码适用于所有浏览器(Chrome,FireFox,Safari,Opera,Netscape,...),但在Internet Explorer中除外!

在注销后的IE中,当我使用CheckMemberAccount.ashx文件检查成员帐户时,会话仍然有效且有效值仍然有效,就像没有签出一样!

此问题仅限于IE !!

请注意,IE设置都是默认设置。

我试过 Global.asax

添加类后,不添加任何代码(只是保持它的默认功能,如Session_Start()),我的问题发生了变化,现在我总是在CheckMemberAccount.ashx的会话中得到null!问题再次出现在IE中!

3天后我没有找到任何解决方案。

我会感激任何帮助:)

1 个答案:

答案 0 :(得分:1)

我相信iM会在浏览器中缓存checkmemberaccount调用。这让我多次陷入困境。在Ajax调用中添加一个随机变量,我相信您的问题将得到解决。

您可以使用像fiddler这样的工具来验证这一点。您应该看到浏览器正在缓存GET请求。您也可以从GET切换到POST。 IE不会缓存POSTS。

顺便说一句......您应该为任何不想缓存的请求修复此问题。