views:

193

answers:

4

The users of my web application may have more than one browser window (or tab) open and pointed to the same page. We're using cookie based session id's, and the user will usually work within the same session id in both browsers/tabs. I would like to be able to uniquely identify which browser window (and tab) that requested an ASP.NET page (in order to make sure, that data stored in the session does not get mixed up).

(e.g. I would be happy if the browser would generate and send a window/tab-id with the http request, as it publishes HTTP_USER_AGENT)

Any ideas?

--thomas

+1  A: 

The Viewstate on each page will be different, maybe you can use some kind of unique identifier created on every page loaded?

Mark Redman
You can then use this identifier to store the actual data under in the active Session. That way, you don't get any (possibly) sensitive data in there, and your ViewState doesn't grow too large.
Thorarin
+1  A: 

It is by default not possible due to the stateless nature of the web, but you could add a "page identifier" that gets generated with each opened page and transmitted for every action.

I'd recommend that you refactor the application in a way that those mixups can't happen, no matter from which page/tab/window the request originates.

dbemerlin
A: 

If I was going to implement something like this I would probably start with a Dictionary<Type, List<Guid>> and store this in the users session. I would also probably make this be a custom type that delegates the dictionary and have a factory method that works similar to

public Guid GeneratePageIdentifier(Page thepage)
{
    var guid = Guid.New();

    if(_dictionary[thepage.GetType()] == null)
        _dictionary[thepage.GetType()] = new List<Guid> { guid };
    else
        ((List<Guid>)_dictionary[thepage.GetType()]).Add(guid);

    return guid;

}

Then embed the guid that's returned from that method on the VIewState of the page. On your page methods that execute actions that you need to validate which page it is you would be able to validate that guid is inside the collection do something. You might also want to implement a custom a type with a guid property to enscapulate more information about why you're doing this or what you need for it to be meaningful.

Chris Marisic
A: 

hi all, if I quickly open two tabs from the same link (example: double click on the mouse wheel) the GUID generated from "var guid = Guid.New();" is the same on the two tabs

anyone have any other ideas to generate a unique identifier for every page?

thanks

Armando
You need to post this as a new question. Click the "Ask Question" link at the top right of the page.
Chris Dwyer