ASP.Net MVC: Configuring asp.net session state in SQL Server.
Step 1: Go
to the command prompt and run the following
commanad
aspnet_regsql.exe -S <ServerName>-E -ssadd -sstype p
where <ServerName> is
the name of the server where your Database is located.
here for my local machine we
have given (local).
Before running the command we
need to check file v4.0.30319 on the
following path
C:\Windows\Microsoft.NET\Framework
if it is not found then we need to install
it.
After running the command it will create database for SQL
session tables.
So now go to the SQL server and there we can see that it has
created Database named “ASPState”.
For more option here is the Link
See the following image.
Step 2: Now go to the Security Tab (outside the Database)>Login >app pool user here
for my local system it is pspl-PC21\pspl
Right click on app pool user (pspl-PC21\pspl) and click on properties.
Following window will be opened.
Go to the user mapping tab in the properties window.
Map the database user for this login by checking check box
in front of Database ASPState.
Also provide database membership for ASPState by checking checkbox of db_owner, db_
executor etc.
Now click on OK.
Step3: After this
we need to make changes in web. config file of the application.
<sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=(local);Initial Catalog=ASPState; Integrated
Security=True;" timeout="3000" />
If you don’t want to use Integrated security then you need
to give the sql user the right to use the AspState database.
And the connection string should look like this
<sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=(local);Initial Catalog=ASPState; User ID=sa;
Password=password1;" timeout="3000" />





Comments
Post a Comment