Dietpixel
Dietpixel

Reputation: 10123

Check if browser accepts cookies

Is there a way that I can check if the browser will allow cookies.

Request.Browser.Cookies 

Doesn't work when cookies are disabled. It says the browser can support them.

The only other thing I can think of is to try to set a test cookie and then check to see if it ever got set.

Is there anyway to make sure cookies are actually enabled.

Upvotes: 5

Views: 17235

Answers (5)

Deepesh
Deepesh

Reputation: 5604

According to MSDN there is no way to determine cookies is allowed or disabled by user. The only way to find it out is through writing it and then reading it.

Check the section "Determining Whether a Browser Accepts Cookies" here.

It also has examples which show how to read and write cookies, and states:

The Cookies property does not indicate whether cookies are enabled. It indicates only whether the current browser inherently supports cookies.

Upvotes: 9

Vipul
Vipul

Reputation: 1583

HttpCapabilitiesBase.Cookies Property gets a value indicating whether the browser supports cookies. See the documentation.

Upvotes: 0

Adam Tuliper
Adam Tuliper

Reputation: 30152

As everyone stated, you essentially need to set, redirect, detect (unless you want only client side detection in that case javascript can do the check) There's a control for this someone wrote.

Upvotes: 1

The Mask
The Mask

Reputation: 17427

I'm don't know other method: set the cookie,check if the cookie exists.

Upvotes: 1

Naor
Naor

Reputation: 24073

I don't know any way to do it in asp.NET. All you can do is to create a cookie and try to read it in the postback.
You can see example of how to do it (this is in vb.NET but I'm sure you can find in google many other examples and in C#): http://forums.asp.net/t/1044823.aspx

Upvotes: 2

Related Questions