Search code examples
c#asp.netsessionweb-configsession-state

how to differ values of same session in different browser tab in asp.net c#


i am creating one web application and there is a requirement where i have to differ values of same session Session["JobNumber"] on different browser tabs. if i make any changes in first tab, these changes should not affect second tab.

i have searched it for this and found same answer in all blogs and SO answers so i tried this :

in web.config file

<configuration>
  <system.web>
    <sessionState cookieless="true"
      regenerateExpiredSessionId="true" />
  </system.web>
</configuration>

on form's page load

if (!IsPostBack)
            {
                PageID.Value = Guid.NewGuid().ToString();
.

.

}

here PageID is:

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

code where i store value in session

var sessionkey = string.Format("Session_{0}", PageID.Value);
            Session[sessionkey] = SelectedNumber;
            Session["JobNumber"] = Session[sessionkey];

this is what i found everywhere so i tried this. but its not working. instead when i log in to my app pop up comes with message error:401. if i remove that code from web.config, this error will disappear.

as 401 is for authentication failure. how the code i have written in web.config relate to that? and strange thing is, pop up message comes saying error:401 still i logged in successfully. any suggestions?


Solution

  • On Page Load:

    PageID.Value = Session["JobNumber"].ToString();
    

    where ever using Session["JobNumber"] , replace it with PageID.Value

    No need of this code in web.config

    <configuration>
      <system.web>
        <sessionState cookieless="true"
          regenerateExpiredSessionId="true" />
      </system.web>
    </configuration>