Losing session data in ASP.NET

前端 未结 9 2266
别那么骄傲
别那么骄傲 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:44
    <httpCookies requireSSL="false" />
    

    Removing this from the local web.config worked for me. The issue was only happening when running the app locally.

    • Removed the setting from web.config
    • Added it to the web.staging.config and web.production.config
    0 讨论(0)
  • 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 */
    }
    
    0 讨论(0)
  • 2021-01-05 17:47

    By default Response.Redirect terminates thread execution and there might be a race conditions in setting session variables. It is described in article Don't redirect after setting a Session variable (or do it right), so try to use another, less violent version:

    Response.Redirect("cpanel.aspx", false); 
    
    0 讨论(0)
提交回复
热议问题