ASP. NET method of saving Session to a database

  • 2020-06-23 00:11:51
  • OfStack

Several ways (not covered in this article) to save Session to SQL Server are as follows:

1. First, create a database to hold Session data, using the command line aspnet_regsql.exe

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 > aspnet_regsql.exe -ssadd -sstype c
-d sd -E

This command adds an sd database to hold session data as windows validation.

2. The SessionState node in ASP. NET web. config file needs to be modified < system.web > Under the


    <sessionState mode="SQLServer" allowCustomSqlDatabase="true"
                  sqlConnectionString="server=.;uid=sa;password=;initial catalog=sd"
                  cookieless="false"
                  timeout="20">
    </sessionState>

In this way, the Session data is no longer dependent on the IIS process but is saved to the database. When you open the sd database, there will be two tables named ASPStateTempSessions and ASPStateTempApplications.


Related articles: