Question

Is it possible to use TempData when cookies are disabled? I have a redirect check that depends on a TempData key, but when cookies are disabled, that key is always null.

Was it helpful?

Solution

TempData is a way to persist something between HTTP requests. Because HTTP is inherently stateless, you can't persist something without having a way to identify the client.

TempData uses the Session as storage, which by default uses cookies to persist a user's session between HTTP requests. A cookie is included in every request with a key to that particular user's session.

If you want TempData to work without cookies, you can set the cookieless="true" attribute of the sessionState tag in your web.config file. That appends a query string parameter to every link in your site to achieve the same result. However, it's not recommended and you will have issues if you're using MVC 4.

If you want it to work without using cookies, include a query string parameter on the target URL instead if possible.

OTHER TIPS

It depends on the TempDataProvider of the Controller. the default provider is SessionStateTempDataProvider which relies on the regular Session State Storage.

That basically means that if Cookies are disabled, you won't have neither Session or TempData unless you'll implement Cookie-less Session.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top