burntmarshmallows
burntmarshmallows

Reputation: 168

Cookies not working with SqlServer session state mode

I have a .NET MVC4 application with the following in my web.config under the system.web section:

<sessionState 
    mode="SQLServer" 
    sqlConnectionString="Data Source=db;userid=user;password=pass;"
    cookieless="false" 
    timeout="20"/>

When I run the site I do not see the cookie on the page nor saved in the database. If I change to cookieless="true" the session id is saved in the database.

How can I get the SqlServer session state to work with cookies?

Upvotes: 1

Views: 1350

Answers (1)

burntmarshmallows
burntmarshmallows

Reputation: 168

The session is saved to the database when a cookie is explicitly added.

Example: HttpContext.Session["Hello"] = "hello";

I assumed that the cookie was generated as soon as the page loaded and when I didn't see it thought I had a problem. But this is incorrect and now I correctly see the cookie when I add to the session state.

Upvotes: 1

Related Questions