views:

197

answers:

1

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

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). So far pretty basic stuff you'd think, and it does work quite nicely too.

Enter 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. 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.

Does anyone have a recommended solution to this, surely exceedingly common, problem?

Many thanks in advance,

JS

+1  A: 

See 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.

For instance, if a page sets a cookie on itself like so:

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.

EricLaw -MSFT-
Thanks for clearing that up, I've since implemented a different solution where the cookie name is generated based on the URL instead. This is far from ideal as it will start overwriting cookies after a certain number of tabs have been clicked (20 in IE I believe).
John Schulze
I've just done a test and after 52 tabs clicked all the cookies are still present according to the "cookie information" tool in IE devtools. That is not what I expected as I've seen in several places that IE will store a maximum of 20 cookies per domain (50 for Firefox). What's going on here?
John Schulze
The cookies-per-domain limit was changed to 50 across all IE versions in August 2007. http://blogs.msdn.com/ie/archive/2007/08/29/update-to-internet-explorer-s-cookie-jar.aspx
EricLaw -MSFT-