views:

209

answers:

3

I need to display a message if the user has cookies disabled. How would I go about doing this?

A: 

The only way is to store a value in cookie and check if you get the value back.

Shoban
+1  A: 

Save some test value and try to re-read it at the next request.

But honestly, your approach is not user friendly. There is hardly any technical reason to deny a service with cookies disabled. You can fall gracefully and just store the values in session.

Anyway, if a user has "In-private" browsing mode on (now available in both IE & FF meaning almost all users) your cookies will anyway be gone after the user's done and there is no way you can detect the "in-private" mode.

User
I agree with the graceful degrade philosophy... +1
Cerebrus
Unfortunately this is a business requirement. I'm a bit too lowly to question those. :)
+1  A: 

You can check the Request.Cookies property which would return an empty HttpCookieCollection.

In Javascript, the usual way to check is the Navigator.cookieEnabled property (works on IE, for other browsers, I think you need to set a cookie and try to read back its value).

Cerebrus