views:

301

answers:

2

I'd like to maintain a session state per browser tab.

Is this easy (or even possible) to do in ASP.NET?

Example: A user hits Ctrl-T in firefox 5 times and visits the site in each tab. I'd like each tab to have its own session state on the server

Thanks

+2  A: 
<configuration>
  <system.web>
    <sessionState cookieless="true"
      regenerateExpiredSessionId="true" />
  </system.web>
</configuration>

http://msdn.microsoft.com/en-us/library/ms178581.aspx

in this case each tab will get unique ID and it will looks like it is another visitor.

zerkms
+1  A: 

To facilitate multi-tab session states for one user without cluttering up the URL, do the following.

Include this somewhere inside your form tag:

<asp:HiddenField ID="PageID" runat="server" />

In your form load function, include:

If Not IsPostaback Then
  'Generate a new PageiD
  Dim R As New Random(DateTime.Now.Millisecond + DateTime.Now.Second * 1000 + DateTime.Now.Minute * 60000 + DateTime.Now.Minute * 3600000)
  PageID.Value = R.Next()
End If

When you save something to your Session State, include the PageID:

Session(PageID.Value & "CheckBoxes") = D

Note: As with session ID's in general, you cannot trust that malicious viewers will not change the SessionID / PageID. This is only a valid solution for an environment where all users can be trusted.

hamlin11
Yes, you can actually overload some core constructor functions in the built-in page classes to accomplish the generation of never-overlapping pageID's (Incremental). This is a nice easy solution however
hamlin11