代码之家  ›  专栏  ›  技术社区  ›  balexandre

IE8不保留会话变量

  •  5
  • balexandre  · 技术社区  · 15 年前

    <%@ 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>
    

    在第一次跑步时,我确实得到了 assigned Session Variable 文本,但单击时会话对象总是 null

    我需要打开/关闭一个选项来使用普通会话变量吗?

    在IIS6.0和Cassini上运行良好(在VS2008和2010下)。

    我开始不知道发生了什么:哦(


    上面示例页面的过程

    alt text

    alt text


    alt text


    screen cast of the situation

    2 回复  |  直到 14 年前
        1
  •  2
  •   Rodolfo    14 年前

    问题可能是域中的下划线。移除∗并查看是否发生相同的情况

        2
  •  0
  •   Radu094    15 年前

    会话ID由浏览器通过本地存储的cookie进行维护。

    你是否在某种保护模式下运行,阻止IE8存储cookies?状态栏上应该有一个红色警告图标。。沿着“…阻止此站点存储cookie”的某些内容

    推荐文章