SessionState in own SQL Server database on windows shared hosting
My ASP.NET site is on Windows Shared Hosting. I need to keep SessionState in SQL Server on my site, and standard way is to use ASPState
DB. But that DB is inaccessible on windows shared hosting, and support said that unfortunately they can't provide me with access to that DB.
Is it possible to use SessionState in the DB that site uses, o开发者_开发知识库r can I create and use any different DB on hosting server to store SessionSate? How can I run the script to create all necessary server objects etc?
Thanks!
You can specify a custom database using a "partition resolver" helper class. The configuration in web.config looks like:
<sessionState mode="SQLServer"
partitionResolverType="YourNameSpace.PartitionResolver"
cookieless="false" timeout="480" />
The class itself looks like:
public class PartitionResolver : IPartitionResolver
{
public void Initialize()
{
}
// The key is a SID (session identifier)
public String ResolvePartition(
Object key)
{
return "Data Source=myServerAddress;Initial Catalog=myDataBase;" +
"User Id=myUsername;Password=myPassword;";
}
}
To create the required SQL Server objects, use the aspnet_regsql
utility. It has an sstype
option you can set to c
to install a custom database.
精彩评论