Search code examples
c#.netsession-stateinprocsql-session-state

How to move the session state from InProc to SQLServer


I am currently using InProc session state mode in my .net web project. I want move that from InProc to SQLServer session state as I am going to use a load balancer. What are the steps that I need to follow?

In my C# code, I use as sessions as below.

    Session["MyValue"] = "Test" // To set
    string value = Session["MyValue"] //To read

So what are the changes that I need to do in source code? Can't I use the same code above when using SQLServer session state?


Solution

  • Follow this documentation. https://msdn.microsoft.com/en-us/library/ms178586.aspx

    You need to do install the Session State Database Using the Aspnet_regsql.exe Tool and do modifications in your web.config.

    <configuration>
      <system.web>
            <sessionState mode="SQLServer"
                 sqlConnectionString="Integrated Security=SSPI;data 
                 source=SampleSqlServer;" />
      </system.web>
    </configuration>