IE8不保留会话变量

发布于 2024-09-17 20:30:44 字数 2304 浏览 5 评论 0原文

如果我托管一个 ASP.NET 页面:

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

在第一次运行时,我确实获得了分配的会话变量文本,但单击后,会话对象始终为null

Id,有一个选项我需要打开/关闭才能使用正常的会话变量?

在 IIS 6.0 和 Cassini(在 VS 2008 和 2010 下)上运行良好。

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

非常感谢任何帮助!


上面示例页面的过程

 alt text

alt text


更多测试表明这种情况仅发生在 IE 中(本例中为 ie8) case), Firefox, Safari, Opera, Chrome 他们都给出了正确的“答案”

alt text


检查情况截屏

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" />  
        <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

alt text

alt text


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

alt text


check the screen cast of the situation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

邮友 2024-09-24 20:30:44

问题可能是域中的下划线。删除 _ 并查看是否发生同样的情况

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

为你拒绝所有暧昧 2024-09-24 20:30:44

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

您是否在某种保护模式下运行以阻止 IE8 存储 cookie?状态栏上应该有一个红色警告图标..“...阻止该网站存储 cookie”

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文