Losing session data in ASP.NET

前端 未结 9 2276
别那么骄傲
别那么骄傲 2021-01-05 16:46

I moved an ASP.NET site running on a server with .NET 1.1 to another server running with .NET 2.0.

In one of the pages I have the following code to detect an expired

9条回答
  •  伪装坚强ぢ
    2021-01-05 17:45

    I encountered this problem when setting the Session variable before a redirect. I had enableSessionState="ReadOnly" in Web.config. It happens because the session does not exists and the redirect happens before the client can set the session cookie.

    My solution was to set a dummy Session variable in the previous page load (login page in my case).

    protected void Page_Load(object sender, EventArgs e)
    {
        // Put this in master page or login page
        Session["createSession"] = true; /* ensure there's a cookie for session */
    }
    

提交回复
热议问题