user287745
user287745

Reputation: 3171

Does the same session continue

Does the same session continue or is a new session created for the same "USER" when a user logs in from computer 'A' using Firefox.

By my understanding, a 'session is created for that user by the server'.

Now, without closing the browser tab, a user opens a new tab and goes to the same page [that would require the user to log in first].

What will happen?

Will the server continue the same session, making the code recognize the user?

Will the server start a new session for this request and destroy the old session?

Consider the same question, but now the user logs in from another browser. What will happen?

Upvotes: 2

Views: 2677

Answers (6)

Kelsey
Kelsey

Reputation: 47726

The sessions are not shared between browsers and are only shared between tabs (or windows) if the new tab/window is spawned from the current page (unless cookieless session handled via the querystring). When you click a link and say open in a new tab or window or choose to duplicate the current tab/window, both tabs/windows will share the same session. This is browser dependant though and each brower could implement it differently.

It's very easy to test. Create a simple aspx page with a Label and a link back to the current page. In the PageLoad do the following:

if (Session["Test"] != null)
{
    Session["Test"] = (int)(Session["Test"]) + 1;
}
else
{
    Session["Test"] = 1;
}

yourLabel.Text = Session["Test"].ToString();

Then open the page using different methods. Use an href with target=_blank. The href will make a new tab/window and share the session but loading the page any other way shouldn't.

Upvotes: 1

František Žiačik
František Žiačik

Reputation: 7612

Sessions are based on cookies in which a Session ID is stored. So, it is purely a matter of how the browser stores it's cookies.

Generally, the browsers share cookies between tabs, so with new tab, the Session ID is preserved and new session will not be created.

Two different browsers, however, don't share the cookies, so in another browser, new session is created.

There are also cookieless sessions. In that case, the session ID is stored in URL (such as http://www.server.com?sessionId=12345). So obviously in this case if you open a new tab and type the address without sessionId, a new one is created too.

Upvotes: 4

Kewley
Kewley

Reputation: 537

If it's a new tab then the same session will be used (because the browser will provide the same session cookie). If it's a different browser, the cookie will not be present and a new session will be started (the session in the other browser will persist assuming your using a standard session mechanism).

Upvotes: 0

spinon
spinon

Reputation: 10847

This really all depend on the site programming. But generally you can see tabs sharing session but different browsers not.

Upvotes: 1

sjobe
sjobe

Reputation: 2837

Sessions generally do not persist across browsers. If the user opens a new tab and goes back to the log in page and logs in again or if he gets automatically logged in all depends on how the back-end code is written.

Upvotes: 0

Franci Penov
Franci Penov

Reputation: 75991

The user session is usually kept in a cookie which is created by the web server, but is actually stored on the client. If the two Firefox tabs share the cookies, the session will be shared between them. However, if the two tabs don't share the cookies, there will be a server session created for each of them.

Upvotes: 0

Related Questions