How do you determine cookies are disabled *without

2019-08-15 09:12发布

问题:

If I disable javascript and cookies, Amazon.com detects that cookies are disabled without a redirect. If you click the cart link, there's only a get on the cart page.

I'm guessing amazon.com is most likely not using ASP.NET, but how would you accomplish detecting disabled cookies using ASP.NET without the use of javascript and redirecting? Is it possible to detect if cookies are disabled in one round trip?

回答1:

I believe what you're describing is impossible. Amazon doesn't appear to do that. As proof:

  1. Disable JavaScript
  2. Clear your cookies (but leave them enabled)
  3. Go here: http://www.amazon.com/gp/cart/view.html/ref=gno_cart

You'll get the message "Please Enable Cookies in your Web Browser to Continue." But if you reload the page, the message will go away, because cookies got set on the first viewing.

The reason this doesn't work is that when a page response sets cookies, the server can't tell they've been properly set until the next request. You can get around that using JavaScript, of course, but without that there's no way for the server to know in advance whether a request comes from a browser that will accept cookies.



回答2:

You don't need redirect to get at the cookies. All you need is a delayed load content.

Basically, I believe the following would work:

The 'GET /index.html' response sets the Cookies (they come in the header, and are stored before index.html is received and rendered).

You can than check for cookies while serving say 'GET /TinyImage.gif' if you don't run into caching problems and respond to images dynamically.

So, the final problem, is how do you inform the user about your findings from the TinyImage request? Definitely not easily, but if you use IFrame instead of a simple tag, you can essentially have two GET requests for a single page render.

Or, you can be really, really insane and actually stall the first GET until the second GET confirms the browser settings. This is for some HTTP wizards, but if you can wrap your head around Comet (not AJAX, Comet!), it can come in handy.

It's definitely possible, just tricky. Would I try doing so in ASP.NET? Can't promise anything but it will be a neat thing to share.



回答3:

I guess it may load the page in the javascript / cookies off configuration and then use javascript to do the check and set functionality to cookies enabled if needed.



回答4:

Could you set a Cookie in Page_Init for instance, then see if you could read from it in Page_PreRender?

Not sure that's even possible, but that's the only way I could think of.