views:

145

answers:

1

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

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

A: 

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"

Radu094
I already made IE settings to be all "low", added the domain to Trusted Sites, in Advanced Settings I even add the options to show un-trust content... but all I do, I get the same (I do restart IE) :o(
balexandre