Asp.net session is null when using IE 10 but works

2019-05-04 20:14发布

问题:

I store some user info in Session["username"] on default.aspx.

Default.aspx.cs:

Session["username"] = txtUsername.Text;
Response.Redirect("page2.aspx", false);

Page2.aspx.cs:

        if (HttpContext.Current.Session["username"] == null)
        {
            WriteLog("Session is null");
        }

It works on most of the machines including Windows Server 2012, but on one server running Windows Server 2012 it doesn't work. It happens only in IE, works fine in Chrome.

Why the session becomes null when running on IE?

IIS and IE has the following settings:

IE settings to Always allow session cookies .

In IIS, session state has these settings:

  1. In Process
  2. Cookie mode=Use Cookies
  3. Time-Out=20 mins
  4. Use Hosting Identity for Impersonation checked