IE8 does not keep Session Variables

你说的曾经没有我的故事 提交于 2020-01-03 14:16:23

问题


If I host an ASP.NET page with:

<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">

    protected void btn_Click(object sender, EventArgs e)
    {
        lbl.Text = HttpContext.Current.Session["a"] == null ? 
                      "null" : 
                      HttpContext.Current.Session["a"].ToString();
    }
    protected void btn_Click2(object sender, EventArgs e)
    {
        lbl.Text = HttpContext.Current.Cache["a"] == null ? 
                      "null" : 
                      HttpContext.Current.Cache["a"].ToString();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            HttpContext.Current.Session["a"] = "CBA";
            lbl.Text = "assigned Session Variable";

            HttpContext.Current.Cache.Add(
                    "a", "ABC", null, 
                    DateTime.Now.AddHours(2), TimeSpan.Zero, 
                    CacheItemPriority.NotRemovable, null);
        }
    }

</script>

<html>
<head>
    <title>Testing Session</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btn" runat="server" Text="read Session" OnClick="btn_Click" />&nbsp;&nbsp;
        <asp:Button ID="btn2" runat="server" Text="read Cache" OnClick="btn_Click2" />
        <hr />
        <asp:Label ID="lbl" runat="server" />
    </div>
    </form>
</body>
</html>

on the first run I do get the assigned Session Variable text, but upon click the Session object is always null

Id there an option I need to turn on/off to use the normal Session Variables ?

works fine on IIS 6.0 and Cassini (under VS 2008 and 2010).

I'm starting to be without ideas on what's going on :o(

Any help is greatly appreciated!


the process of the example page above


More tests shows that this only happens in IE (ie8 in this case), Firefox, Safari, Opera, Chrome they all give the correct "answer"


check the screen cast of the situation


回答1:


the problem may be the underscores in the domain. remove the _ and see if the same thing happens




回答2:


Session ID's are maintained via a locally stored cookie by the browser.

Are you running in some sort of protected mode that prevents IE8 from storing cookies? There should be a red warning icon on the status bar.. something along the "...prevented this site from storing a cookie"



来源:https://stackoverflow.com/questions/3658513/ie8-does-not-keep-session-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!