Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net - session - multiple browser tabs - different sessions?

I'd like to maintain a session state per browser tab.

Is this easy (or even possible) to do in ASP.NET?

Example: A user hits Ctrl-T in firefox 5 times and visits the site in each tab. I'd like each tab to have its own session state on the server

like image 630
Brian Webster Avatar asked May 15 '10 15:05

Brian Webster


People also ask

How do browser tabs differ sessions?

jsp ), type your name in the input and submit the form. Then open a new tab in the same browser, and then you can see your name (get from the session) on the new tab. Be careful with the browser-cache, sometimes seems that it doesn't happen, but it's in the cache, refresh the second tab. Thanks.

Do browser tabs Share sessions?

Scenario: By default all browsers share session state between multiple tabs. So if you logged into one tab with particular site and open internal link of the same site in new tab, you need not to worry to login again. It will automatically declare you as logged in user.

How PHP handle session in multiple tabs in a browser?

To distinguish between tabs you just have to check $_COOKIE['tab_id'] on the server and store sessions values appropriately. Do note that Firefox behaves strangely, in that triggering window. open() will create a window that shares sessionStorage with its parent, giving you two tabs with the same ID.


1 Answers

To facilitate multi-tab session states for one user without cluttering up the URL, do the following.

In your form load function, include:

If Not IsPostback Then   'Generate a new PageiD'   ViewState("_PageID") = (New Random()).Next().ToString() End If 

When you save something to your Session State, include the PageID:

Session(ViewState("_PageID").ToString() & "CheckBoxes") = D 

Notes:

  • As with session ID's in general, you cannot trust that malicious viewers will not change the SessionID / PageID. This is only a valid solution for an environment where all users can be trusted. Fortunately, ViewState does offer more protection than using a hidden input field.
  • You will not have access to the PageID until the ViewState is restored upon PostBack. Therefore, you will not have access to the PageID in the page_init() handler.
like image 113
Brian Webster Avatar answered Sep 19 '22 09:09

Brian Webster