views:

38

answers:

3

consider this, If one is user of a Web application

like :

A someone visits SomeWebSite.com as a normal User (registered)

HttpCookie cookie = new HttpCookie("LastVisit");
cookie.Value = DateTime.Now.ToString();
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);

B visits SomeWebSite.com, using another account as a moderator / admin

HttpCookie cookie = new HttpCookie("LastVisit");
cookie.Value = DateTime.Now.ToString();
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);

Both cookies belong to same domain, but for two different Accounts. How does browser know Which cookie belongs to which account ? if we use the following code to access it.

if (Request.Cookies["LastVisit"] != null)
    {
       string lastTimeUserVisited = Request.Cookies["LastVisit"].Value;
    }

EDIT: It's my first time ever to work on cookies.

I do appreciate your patience

+2  A: 

I don't quite understand the question. A single browsing session won't distinguish between the two cookies. The last cookie that the server sets replaces the previous ones. Obviously, two instances of Chrome running on two different computers don't share cookies and each send their own instance of the cookie to the server in every request.

Mehrdad Afshari
A: 

How does browser know Which cookie belongs to which account?

It doesn't. The cookie for the second visit overwrites the cookie for the first. If you want that to be different, you have to use different cookie names, e.g. by appending the user ID to the cookie name.

Michael Borgwardt
+1  A: 

If the users are logged in using the same user account on the computer, they will be using the same set of cookies.

If they are logged in using separate user accounts, they will each have their own set of user folders and thus their own browser settings and their own set of cookies.

Guffa