如何检查Classic ASP中是否启用了会话cookie?

时间:2023-01-31 07:29:00

What's an elegant way in Classic ASP to check if session cookies are enabled in a user's browser using server side code (because javascript might be disabled as well).

在Classic ASP中,使用服务器端代码检查是否在用户的浏览器中启用会话cookie是一种优雅的方式(因为javascript也可能被禁用)。

I have a solution of my own but it looks ugly as hell.

我有自己的解决方案,但看起来很难看。

@James - that doesn't differentiate between setting a session cookie and a general purpose cookie though (IE lets you differentiate between First Party, Session Cookies and Third Party, but I see with Firefox they only differentiate between First Party and Third Party)? I'm setting a session value in a login page then doing a Response.Redirect kinda thing and checking to see if the session value is still valid.

@James - 虽然没有区分设置会话cookie和通用cookie(IE允许你区分第一方,会话Cookie和第三方,但我看到Firefox只能区分第一方和第三方)?我正在登录页面中设置会话值,然后执行Response.Redirect有点事情并检查会话值是否仍然有效。

2 个解决方案

#1


2  

Unless you specify an expiry on the cookie it will be a session cookie. The term session is a bit overloaded in HTTP. When the IE dialog refers to a session cookie it means any cookie that is only stored in process memory and not persisted to disk, therefore only lives for the duration of the process (the session). Start another IExplore.exe process and you have another session which will not have the values of any previous or extant session cookies.

除非您在cookie上指定过期,否则它将是会话cookie。术语会话在HTTP中有点过载。当IE对话框引用会话cookie时,它表示任何仅存储在进程内存中但不持久保存到磁盘的cookie,因此仅在进程(会话)期间存在。启动另一个IExplore.exe进程,你有另一个会话,它将没有任何以前或现有的会话cookie的值。

You are correct though that you can test whether even session level cookies are being blocked by just storing a value in the session object and testing for its presence on a redirect.

您是正确的,但您可以通过仅在会话对象中存储值并测试其在重定向上的存在来测试是否阻止会话级cookie。

#2


1  

Well, the "ugly as hell" method we used, was to set a cookie and redirect to a new page. In the code for the new page, see if the cookie was set. Since the only way to get to the second page is to be redirected there when the cookie is set, it's presence or absence should tell the state of the browser.

好吧,我们使用的“丑陋的地狱”方法是设置一个cookie并重定向到一个新的页面。在新页面的代码中,查看cookie是否已设置。因为在设置cookie时,到达第二页的唯一方法是重定向,所以它的存在与否应该告诉浏览器的状态。

#1


2  

Unless you specify an expiry on the cookie it will be a session cookie. The term session is a bit overloaded in HTTP. When the IE dialog refers to a session cookie it means any cookie that is only stored in process memory and not persisted to disk, therefore only lives for the duration of the process (the session). Start another IExplore.exe process and you have another session which will not have the values of any previous or extant session cookies.

除非您在cookie上指定过期,否则它将是会话cookie。术语会话在HTTP中有点过载。当IE对话框引用会话cookie时,它表示任何仅存储在进程内存中但不持久保存到磁盘的cookie,因此仅在进程(会话)期间存在。启动另一个IExplore.exe进程,你有另一个会话,它将没有任何以前或现有的会话cookie的值。

You are correct though that you can test whether even session level cookies are being blocked by just storing a value in the session object and testing for its presence on a redirect.

您是正确的,但您可以通过仅在会话对象中存储值并测试其在重定向上的存在来测试是否阻止会话级cookie。

#2


1  

Well, the "ugly as hell" method we used, was to set a cookie and redirect to a new page. In the code for the new page, see if the cookie was set. Since the only way to get to the second page is to be redirected there when the cookie is set, it's presence or absence should tell the state of the browser.

好吧,我们使用的“丑陋的地狱”方法是设置一个cookie并重定向到一个新的页面。在新页面的代码中,查看cookie是否已设置。因为在设置cookie时,到达第二页的唯一方法是重定向,所以它的存在与否应该告诉浏览器的状态。