locked
State Server is losing sessions in between RRS feed

  • Question

  • User-978397479 posted

    I have a .NET MVC 4.5 application. It is hosted on 2 servers and it is load balanced using a VIP. All the users access the website using the VIP.

    We have used ASP.NET State Server for storing session data. 1 of the server has the app hosted and is the state server.

    We have some roles specified for a user, based on which some icons are set to visible/invisible. The roles are stored in the session itself.

    The problem is that the icons disappears on refresh and if I refresh it again, it loads the icons back. On frequent F5 the same happens multiple times.

    Based on the research on the internet, I checked the application ID under IIS is the same (its same), same configurations are loaded on both the servers. We have session timeout set to 60 in the code itself, web.config is not updated through code and neither any other files are updated when the app runs, response.redirects are not used anywhere in the code, no logs inside my event viewer.

    Sometimes, the users are logged out too. Hence, I determined that this is a session issue.

    Can anyone please help me here ?

    Friday, November 17, 2017 7:11 PM

All replies

  • User475983607 posted

    Both server must use the same machine key otherwise only the server that created the Session can decrypt the Session cookie.

    Friday, November 17, 2017 7:47 PM
  • User-978397479 posted

    Currently, I have this config.

    <sessionState xdt:Transform="Insert"

                      mode="StateServer"

                      stateConnectionString="tcpip=XXX.XXX.XXX.XXX:42424"

                      timeout="60"></sessionState>

    is there anything else that I have to add or change ?

    Friday, November 17, 2017 8:08 PM
  • User475983607 posted

    Currently, I have this config.

    <sessionState xdt:Transform="Insert"

                      mode="StateServer"

                      stateConnectionString="tcpip=XXX.XXX.XXX.XXX:42424"

                      timeout="60"></sessionState>

    is there anything else that I have to add or change ?

    Both application must use the same machine key.  By default, the machine key is set to autogenerate. 

    Please see the Session-State mode documentation.

    https://msdn.microsoft.com/en-us/library/ms178586.aspx

    To use StateServer mode in a Web farm, you must have the same encryption keys specified in the machineKey element of your Web configuration for all applications that are part of the Web farm. For information on how to create machine keys, see article 313091, "How to create keys by using Visual Basic .NET for use in Forms authentication," in the Microsoft Knowledge Base at http://support.microsoft.com

    Friday, November 17, 2017 9:37 PM
  • User-978397479 posted

    Now i implemented same machine keys. Still the problem exists. 

    Any other suggestion ?

    Saturday, November 18, 2017 7:35 PM
  • User475983607 posted

    Now i implemented same machine keys. Still the problem exists. 

    Any other suggestion ?

    You can reproduce the error which is good.  I would come up with a troubleshooting plan.  The idea is to eliminate items until you find the casue.  If you feel the issue is Session related, then write a bit of logging code that writes to a file, the event viewer, or DB when Session is empty.  The log will tell if one server has an issue or both.  If it is one server has the issue then perhaps it's configuration or object serialization.

    Keep in mind, this can be a bug in the application and have nothing to do with Session.  

    Is the application throwing exceptions?  Make sure that you are not hiding exceptions in try...catch blocks.

      

    Sunday, November 19, 2017 5:05 PM
  • User-707554951 posted

    Hi sameer.s.panicker

    By default, State Server service is set up to start manually. Change startup type to Automatic so it will run again if computer restarts.

    Then to edit <sessionState> element in web.config to configure ASP.NET web application to use State Server. Like this:

    <sessionState
    
         mode="StateServer"
    
         stateConnectionString="tcpip=127.0.0.1:42424"
    
    />

    Besides, do not use InProc session state mode. If you do, data loss can occur if different requests for the same session are served by different worker processes.

    Related links

    https://stackoverflow.com/a/3516058

    http://www.beansoftware.com/ASP.NET-Tutorials/Store-Session-State-Server.aspx

    https://blogs.msdn.microsoft.com/tess/2009/06/26/a-case-of-lost-session-variables-when-using-out-of-process-session-state/

    Best regards

    Cathy

    Monday, November 20, 2017 9:48 AM