检查浏览器是否接受cookie
有没有办法检查浏览器是否允许cookies。
Request.Browser.Cookies
禁用 cookie 时不起作用。它说浏览器可以支持它们。
我唯一能想到的另一件事是尝试设置一个测试 cookie,然后检查它是否已设置。
无论如何,有没有办法确保 cookie 确实已启用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据 MSDN,无法确定用户是否允许或禁用 cookie。找到它的唯一方法是先写然后读。
请查看此处的“确定浏览器是否接受 Cookie”部分。
它还提供了一些示例,展示了如何读取和写入 cookie,并指出:
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:
我不知道在 asp.NET 中有什么方法可以做到这一点。您所能做的就是创建一个 cookie 并尝试在回发中读取它。
您可以查看如何执行此操作的示例(这是在 vb.NET 中,但我确信您可以在 google 中找到许多其他示例和 C# 示例): http://forums.asp.net/t/1044823.aspx
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
我不知道其他方法:
设置cookie,检查cookie是否存在。
I'm don't know other method:
set the cookie,check if the cookie exists.
正如大家所说,您本质上需要设置、重定向、检测(除非您只想进行客户端检测,在这种情况下 javascript 可以进行检查)
有有人为此编写了一个控件。
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.
HttpCapabilityBase.Cookies 属性获取一个值,指示浏览器是否支持 cookie。 请参阅文档。
HttpCapabilitiesBase.Cookies Property gets a value indicating whether the browser supports cookies. See the documentation.