HttpCookie Class Non Readable Members

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What properties on a HttpCookie give invalid information when you read it
from the Request object?

For example if you run this code, I believe the domain, expires, and
HttpOnly do not tell the truth.

protected string CookieList_Get()
{

HttpCookie cookie;
StringBuilder sb = new StringBuilder();
try
{
sb.Append("<p><b> Cookie List</b></p>");


for ( int i = 0; i <=
HttpContext.Current.Request.Cookies.Count-1; i++)
{
cookie = HttpContext.Current.Request.Cookies;

sb.Append("<b>Cookie: " + cookie.Name + " </b> " +
System.Convert.ToString(i + 1) + " of " +
System.Convert.ToString(HttpContext.Current.Request.Cookies.Count) + "<br
/>");

sb.Append(" Expires: " + cookie.Expires + "<br />");
sb.Append(" Secure: " + cookie.Secure + "<br />");
sb.Append(" Domain: " + cookie.Domain + "<br />");
sb.Append(" Path: " + cookie.Path + "<br />");
sb.Append(" HttpOnly: " + cookie.HttpOnly + "<br />");

if (cookie.HasKeys)
{
for (int j = 0; j < cookie.Values.Count-1; j++)
sb.Append(" Value(" +
System.Convert.ToString(j) + "): " + cookie.Values.GetKey(j) + ": " +
cookie.Values[j] + "<br />");
}
else
{
sb.Append(" Value: " + cookie.Value + "<br />");
}


}
}
catch (Exception ex)
{
return ex.Message;
}
return sb.ToString();
}
 
this is because the browser does not send the values with the request.
it uses them to decide whether to send the cookie. the browser only
sends the cookie name and value in the header.

these values are set in the response cookie.


-- bruce (sqlwork.com)
 
Hi Chuck,

IE will simply send all cookies belongs to the domain to server.

One note about localhost: if you're using built-in web server to debug
several ASP.NET web sites locally, although they're not using the same
port, they belong to the same domain and the cookies will be seen from each
other in Request.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
By the way, you can use this tool to view cookies more easily:

#IECookiesView v1.70: Cookies viewer/manager for Internet Explorer
http://www.nirsoft.net/utils/iecookies.html


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top