检查浏览器是否接受cookie

发布于 2024-11-28 08:22:25 字数 200 浏览 1 评论 0原文

有没有办法检查浏览器是否允许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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧梦荧光笔 2024-12-05 08:22:25

根据 MSDN,无法确定用户是否允许或禁用 cookie。找到它的唯一方法是先写然后读。

请查看此处的“确定浏览器是否接受 Cookie”部分。

它还提供了一些示例,展示了如何读取和写入 cookie,并指出:

Cookies 属性并不指示是否启用 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:

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

半﹌身腐败 2024-12-05 08:22:25

我不知道在 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

久夏青 2024-12-05 08:22:25

我不知道其他方法:
设置cookie,检查cookie是否存在。

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

尐偏执 2024-12-05 08:22:25

正如大家所说,您本质上需要设置、重定向、检测(除非您只想进行客户端检测,在这种情况下 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.

梦途 2024-12-05 08:22:25

HttpCapabilityBase.Cookies 属性获取一个值,指示浏览器是否支持 cookie。 请参阅文档。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文