Hi,
This morning I accidentally saw the following snippet code, I was fairly surprised because it work very well.
Don't look at its logic please, I'm just curious why does the HttpCookieCollection (Request.Cookies in this case) return a string (cookie name) instead of a HttpCookie object in foreach loop. Is it a consistency issue because we normally get HttpCookie object in this collection by index/name?
Thanks,
foreach (string cookieKey in System.Web.HttpContext.Current.Request.Cookies)
{
HttpCookie tmpCookie = System.Web.HttpContext.Current.Request.Cookies[cookieKey];
if (tmpCookie != null && tmpCookie["RecentlyVisited"] != null)
{
cookie.Add(tmpCookie);
}
}