简体   繁体   English

REST的cookie路径在IE中失败而没有尾随斜杠

[英]RESTful cookie path fails in IE without trailing slash

I have been asked to build a tabbed section on pages that have RESTful URLs without a trailing slash (.NET MVC), for example http://myhost/books/the-amber-spyglass 我被要求在具有RESTful URL且没有斜杠(.NET MVC)的页面上构建选项卡式部分,例如http:// myhost / books / the-amber-spyglass

For the tabbed sections to be a bit more user friendly I want them to remember which tab was open on each page as the user moves around, so that if they return to a book they were previously on the same tab remains opened. 为了使标签部分更加用户友好,我希望他们记住当用户四处移动时在每个页面上打开哪个选项卡,这样如果他们返回到一本书,他们之前在同一个选项卡上仍然打开。 This is achieved by setting a cookie named "tab" with value set to the tabid and path set to the page they are on (so it doesn't affect tabs on other pages). 这是通过设置名为“tab”的cookie来实现的,其中值设置为tabid,路径设置为它们所在的页面(因此它不会影响其他页面上的选项卡)。 So far pretty basic stuff you'd think, and it does work quite nicely too. 到目前为止,你认为是非常基本的东西,它确实也很好用。

Enter Internet Explorer. 进入Internet Explorer。

In IE it turns out a cookie with path /books/the-amber-spyglass will NOT match the above URL and consequently won't get set properly. 在IE中,它显示了一个带有路径/书籍/琥珀色 - 望远镜的cookie与上述URL不匹配,因此无法正确设置。 If I add a trailing slash so the path is /books/the-amber-spyglass/ instead it works fine - but I cannot change our URL schema, and even if I could "the-amber-spyglass" is a resource, NOT a folder. 如果我添加一个尾部斜杠,所以路径是/ books / the-amber-spyglass /而不是它工作正常 - 但我无法更改我们的URL模式,即使我可以“琥珀 - 望远镜”是一种资源,而不是夹。

Does anyone have a recommended solution to this, surely exceedingly common, problem? 有没有人有一个推荐的解决方案,这肯定是非常常见的问题?

Many thanks in advance, 提前谢谢了,

JS JS

See http://blogs.msdn.com/ieinternals/archive/2009/08/20/WinINET-IE-Cookie-Internals-FAQ.aspx http://blogs.msdn.com/ieinternals/archive/2009/08/20/WinINET-IE-Cookie-Internals-FAQ.aspx

Due to an obscure bug in the underlying WinINET InternetGetCookie implementation, IE's document.cookie will not return a cookie if it was set with a path attribute containing a filename. 由于底层WinINET InternetGetCookie实现中存在一个模糊的错误,如果使用包含文件名的路径属性设置,IE的document.cookie将不会返回cookie。

For instance, if a page sets a cookie on itself like so: 例如,如果页面设置了一个cookie,就像这样:

Set-Cookie: HTTPSet-PathCookie=PASS;path=/check.htm Set-Cookie:HTTPSet-PathCookie = PASS; path = / check.htm

…the cookie will be sent with HTTP requests but will not appear in the document.cookie collection. ... cookie将与HTTP请求一起发送,但不会出现在document.cookie集合中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM