问题
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.
回答1:
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.
回答2:
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
回答3:
I'm don't know other method: set the cookie,check if the cookie exists.
回答4:
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.
回答5:
HttpCapabilitiesBase.Cookies Property gets a value indicating whether the browser supports cookies. See the documentation.
来源:https://stackoverflow.com/questions/6964481/check-if-browser-accepts-cookies