Introduction
While working on SharePoint Server 2019 (on-premise) high-availability setup, client asked to enable session state in the SharePoint production farm, as previously they have faced the issue in high-availability setup via load balancer that whenever any user performs some activity and session is stable for few minutes, the user gets logged out of the application and then user has to login again to access the application, which means user's session is not persisted.
Description
As you might know that ASP.NET Session state is disabled by default in SharePoint installation, however if you are working with custom solutions, web-parts, third pary tools, etc., persisting the user information per session is very much important and required. So, in this article, I will explain how you can enable session state in SharePoint 2019.
Note
ASP.NET allows persisting session states in below three different ways and it is always a good practice to enable the session state at SQL Server (database) -
- On server memory as an InProc
- On SQL Server to persist session in database (preferred method)
- On Session State Server to persist session on dedicated server memory
Step 1
Enable ASP.NET Session State Service - ASP.NET Session state can be enabled in the SharePoint farm by enabling "SharePoint Server ASP.NET Session State Service" service application on the SharePoint farm. This service application cannot be enabled using SharePoint's Central Administration interface. This service application can be enabled using below PowerShell command -
Enable-SPSessionStateService –DefaultProvision
By default, this will create service application database with "SessionStateService_<GUID>", on the database server where SharePoint's farm configuration database is located and will be provisioned using Windows credentials of the logged in user.
In case you want to create the service application with specific database name, then use the below PowerShell command -
Enable-SPSessionStateService -DatabaseServer <YourDBServerName> -DatabaseName <YourDBName>
Step 2
Check the SharePoint Server ASP.NET Session State Service in Manage Service Applications in SharePoint's Central Administration -
Step 3
Check if the default service application database is created in the database server -
Step 4
The above PowerShell command adds the module in web.config of all the web applications in the farm. Kindly note, that if you have multiple servers in the farm, then module will be added automatically in the web.config file of all the web-front servers, as such you don't need to add any entry manually in web.config file.
Secondly, a "sessionstate" entry will be created in all the web applications in the farm, as shown in below image -
Note
As shown in above image, by default, it would create session for 60 minutes. If you want to increase or decrease session expiration, you can pass "SessionTimeout" parameter while creating ASP.NET Session State Service using Enable-SPSessionStateService command.
Step 5
To ensure that SharePoint web application gets activated to persist ASP.NET sessions, the web.config file needs to be manually updated for the specific SharePoint web application on all web-front servers in the farm. Search for <pages enableSessionState in web.config. By default, its value will be False, you have to make this property as True, as shown in below image -
Note
- The web.config path of web application is: C-drive -> inetpub -> wwwroot -> wss -> VirtualDirectories -> WebApplicationPortNumber
- Please take the backup of web.config file before making any manual changes in the web.config file.
I hope by using the information in this article, you will be able to implement session management in SharePoint 2019 farm.