0

First, I am new to Web app programming. I come from Desktop apps (WinForms & WPF). Recently I have been assigned a project that was made in the past by ohter people. This project is done in ASP.NET MVC and it uses an InProc session state mode.

Now, I want to build a web gardening, that is, use multiple worker process for the application pool. I have googled and I have discovered that InProc session does not work with web gardening because each worker process within app pool uses its own session state. So I am planning to switch it into another session state mode such as State Server or SQL Server.

Now I have a doubt. Apart from changing session state mode in Web.config:

<configuration>  
  <system.web>      
    <sessionState mode="InProc" timeout="25"></sessionState>  
  </system.web>  
</configuration>

... Do I need to do some extra work? for example reprogramming the ASP.NET MVC app, configuration or some other things in order it to work?

Below I share some interesting links:

Willy
  • 9,848
  • 22
  • 141
  • 284
  • 1
    From your application perspective it's *mostly* transparent. It's just that the data you read and write to/from `HttpContext.Session` is persisted differently under-the-hood. But, since objects you store in session now have to be serialized (since they're no longer in-memory), you might encounter serialization issues due to this change. – haim770 May 26 '19 at 13:30
  • Ok so since objects stored in session should be serialized now, I understand code in ASP.NET MVC web application should be modified, right? – Willy May 27 '19 at 07:44
  • 1
    It depends on the kind of objects you store in `Session`. See https://learn.microsoft.com/en-us/previous-versions/dotnet/articles/aa479041(v=msdn.10)#state-serialization-and-deserialization – haim770 May 27 '19 at 07:52

1 Answers1

0

For web farms you should keep your session either in StateServer or Sql Server. To do so you need to add following configuration

     <connectionStrings>
           <add name="ConnectionString1" 
           connectionString="Data Source=YourServer;Initial 
           Catalog=SessionDatabase;Integrated Security=True"
           providerName="System.Data.SqlClient" />
    </connectionStrings>



<!--Change your <sessionState mode="InProc" timeout="25"></sessionState>  to this.-->

<sessionState mode="SQLServer" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="ConnectionString1" />
  </providers>

  • Using SQL Server state session, apart from it, do I have to create some database and tables for that? Do I have to modify code in ASP.NET MVC app? – Willy May 27 '19 at 07:46
  • 1
    Good tutorial for creating session database : http://youtube.com/watch?v=o-8vjQu6SmI&t=765s And Microsoft's documentation : http://learn.microsoft.com/en-us/previous-versions/dotnet/… – javidg 8 hours ago – Javid Gahramanov May 28 '19 at 05:15