ASP.NET MVC Session.IsNewSession issue with Google Chrome

前端 未结 2 2029
悲哀的现实
悲哀的现实 2021-01-02 13:32

I\'m currently working on a Session expired piece of logic for my ASP.NET 3.5 MVC 2 project to log out a user and redirect them to the AccountController LogOn action.

<
相关标签:
2条回答
  • 2021-01-02 14:22

    ASP.NET will create a new session for every request unless you store something in it. Try adding the code below to your Global.asax. It works in my MVC2 and MVC3 apps with the same SessionExpireFilterAttribute.

    protected void Session_Start()
    {
        Session["Dummy"] = 1;
    }
    
    0 讨论(0)
  • 2021-01-02 14:26

    We can add session_start method in Golbal.asax file in MVC appliaction.

      protected void Session_Start(object sender, EventArgs e)
          {                    
           HttpContext.Current.Session.Add("UserId" , null);
          }
    

    Then when application starting your session will be created. and then session will be not isNewSession 'True', otherwise it will be always 'True'

    0 讨论(0)
提交回复
热议问题