1

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, or 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!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.