Unique session in multiple browser tabs in ASP.NET MVC

后端 未结 3 1543
遥遥无期
遥遥无期 2020-12-16 03:54

I want to create unique session whenever user open a new browser tab or window in ASP.NET MVC application. Is it possible in ASP.NET / MVC ?

I tried to follow below

3条回答
  •  孤城傲影
    2020-12-16 04:18

    A variation of the first answer, with HTML 5, is to use window.sessionStorage instead of setting window.name. So you could do something like this on the entry page of your application:

    var uniqueId = "<%= Guid.NewGuid().ToString() %>";
    window.sessionStorage.setItem("tabId", uniqueId);
    

    Then in every controller action that requires a session you pass the parameter with:

    window.sessionStorage.getItem("tabId");
    

提交回复
热议问题