usefulBee
usefulBee

Reputation: 9692

How to uniquely identify each new browser tab/window?

I am trying to implement the idea found here in order "To facilitate multi-tab session states"

The shared solution speaks of Web Forms and wondering if it is possible to get a unique id for each new tab in asp.net MVC in order to use for each instance of session variables.

Upvotes: 0

Views: 1451

Answers (1)

Wurd
Wurd

Reputation: 475

You won't be able to reliably check if a user has closed a tab in MVC due to the nature of restful Http requests.

If it's absolutely essential to keep track of open tabs I would think about SignalR, you can reliably track open tabs in real time using that. You would have to implement a collection of unique session objects synced to a unique ID on the matching tab. On submitting the form you would match the session by ID to the ID passed in by the form.

Having said that I would be very cautious about keeping anything specific to a certain page/tab in a session. It can lead to many confusing bugs that are very hard to debug, often leading to complete reworks.

Upvotes: 2

Related Questions