Search code examples
asp.net.netbrowseridentify

Identify Unique Browser / tab instance, e.g. User has 2 tabs open on mysite.com-identify each


I have read this and many other links the past few days.

The problem is that I need to have a unique identifier for each tab or browser that a user has open for mysite.com (example site name)

I cannot use a unique session, as when I open mysite.com and have e.g. selected "carrots" in the session, then all the other tabs/browsers for mysite.com now has "carrots" in the specific session value.

But still the server obviously identifies each browser/tab uniquely. Is there a way to get hold of this unique browser/tab ID, or to create a unique one?

I am not referring to generating a unique ID oneself via JavaScript, I saw some good examples on StackOverflow. The problem would be that I'd need to implement it on each master page and carry it around between master/non master pages. Also for e.g. In my instance it won't work as I can have the browser open and it would generate 20 different IDs if I ran it 20 times across a few pages e.g. when I cannot transfer the value across ports.

So please, not to waste everyone's time, this is not a random GUID creation question, this question relates to obtaining a unique recreatable ID (if it gets lost)for each tab/browser, preferably identifying by the link to the server.


Solution

  • This is a big topic you've touched on. If you only need to persist the ID during a form submit, you can take the approach of the client-side window.name property and use the window.onload to propagate a hidden field with that value. But this won't work when user is following hyper-links (click on a link on a site). onload: check if window.name is set; if not set, assign a GUID. if set, set a hidden field=window.name. So, on submit, your form will have the hidden field with the window.name GUID.

    You can also use the HTML5 window.sessionStorage which will solve all your troubles, but that don't work on older browsers.

    If you need support backward-browser AND non-submit type, then you will need to write some pretty complex cookie/session management on the client side. Not pretty. Just hope the above 2 is sufficient.