Thursday 10 September 2020

ASP.NET State Server

 How to Store Session Data in ASP.NET State Server

ASP.NET Session State allows four modes to specify where you want to store session data: InProc, SQLServer, State Server and Custom. Default mode InProc, is fastest and default mode, but not useful in many scenarios. One of the significant problems is that sessions stored InProc are deleted every time when application restarts. This could happen pretty often.

If your user was in the middle of long task like populating long order form or survey; or reading of license agreement etc., all his previously saved session data will be lost, and he or she must start process from the beginning.

Also, default InProc mode doesn't support multiple servers (web farms) and multiple processors (web gardens). If your website is running on multiple web servers or multiple processors, you have to keep sessions out of ASP.NET process.

As solution for all of these problems, as more reliable and scalable options, ASP.NET introduces State Server and SQL Server. Both State Server and SQL Server stores sessions outside of ASP.NET process, so they are appropriate solution for web farm scenario.

What is ASP.NET State Server?

State Server is implemented as Windows service. File of State Server is aspnet_state.exe. This file is located on [SystemFolder]\Microsoft.Net\Framework\[.Net Framework Version Number]\aspnet_state.exe. Example location for ASP.NET 4.0 could be:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_state.exe

How to use Session State service

First, be sure that State Server windows service is running. Check in Windows Control Panel --> Services and assure that "ASP.NET State Service" is started. You can also start state service using command prompt with line:

 net start aspstate 

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

Second step is 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" />

That is all. Now you can start ASP.NET application and session data will be stored out of application process, in State Server.

Reference1, Reference2

0 comments:

Post a Comment

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (43) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (47) CD (1) CI (2) CloudComputing (2) Coding (7) CQRS (1) CSS (2) Design_Pattern (6) DevOps (4) DI (3) Dotnet (8) DotnetCore (16) Entity Framework (2) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) Lamda (3) Linq (11) microservice (3) Mongodb (1) MVC (46) NodeJS (8) React (11) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (1) UI (1) UnitTest (1) WCF (14) Web Api (15) Web Service (1) XMl (1)

Dotnet Guru Archives