Way around ASP.NET session being shared across multiple tab windows

后端 未结 6 693
半阙折子戏
半阙折子戏 2020-12-09 17:17

I\'m storing some value in an asp.net session on the first page. On the next page, this session value is being read. However if multiple tabs are opened and there are multip

6条回答
  •  忘掉有多难
    2020-12-09 18:02

    Could you use ViewState instead of SessionState?

    Update:

    Or perhaps a combination of ViewState and SessionState.

    Here's an example sequence:

    • On Page 1, user chooses "Red". Value is stored in SessionState.
    • User navigates to Page 2. Value is read from SessionState and stored in ViewState of Page 2.
    • User opens a second Page 1 in a new tab and chooses "Blue". Value is stored in SessionState, so "Red" is replaced with "Blue".
    • User navigates to Page 2. Again, value is read from SessionState and stored in ViewState.
    • User returns to original Page 2 (the one on the first tab) and performs a PostBack. Value is read from ViewState. Value is still "Red".
    • User returns to second Page 2 (the one of the second tab) and performs a PostBack. Value is read from ViewState. Value is still "Blue".

    In other words, use SessionState for transitions between pages. Use ViewState for PostBacks of same page.

    Does that help?

提交回复
热议问题