Nachiket Mehta
Nachiket Mehta

Reputation: 310

New session per browser tab/window in ASP.NET MVC 3 app

I need to have a new session per browser window/tab. I am aware of the fact that ASP.NET assigns one session per process. I am also aware that browsers share this session between all open tabs/windows of the app. However, I need to come up with a way to create a new session for a new tab/window.

Cookieless session-state is not an option also. I already looked at that. I am looking to keep URL's clean.

I looked at the following solutions. 1) asp.net - session - multiple browser tabs - different sessions?. This solutions suggests using IsPostBack property, which is not available in MVC. 2) https://sites.google.com/site/sarittechworld/track-client-windows. This one looks very complex and I don't fully understand the javascript magic that is happening in it. I don't want to put in a solution that I don't understand. Also, I am not fully aware of any security holes that this solution may create.

Can someone point me in the right direction?

Upvotes: 6

Views: 6923

Answers (2)

user2208790
user2208790

Reputation: 11

I've created a NuGet package called ASP.NET MVC Conversational Session. Here you find more information: http://blog.micic.ch/net/asp-net-mvc-conversational-session

I released the first version yesterday. Have a look at the demo code or download the demo solution and let me know if there are things to improve. :)

EDIT: By default: The "identifier" is passed via URL when you use the appropriate extension method in the View. But you can add the identifier on your own. It gives you more flexiblity. (For example when you have links which are not generated via @Html.ActionLink.. etc.)

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

The only way to achieve this is to append the session id in the url which is what cookieless sessions are intended to do. Unfortunately you seem to have ruled out this possibility due to the ugly urls it produces.

Upvotes: 1

Related Questions