Feroze
Mon Jan 26 19:56:35 CST 2004
Thanks for that info.
WebHeaderCollection() class is a generic API for managing headers. It does
not have any knowledge about what the Semantics/syntax of the particular
header values are. When it sees a header, it will try to use the RFC
semantics for parsing the header values (if you call GetValues()). It does
not know that this is a "Set-Cookie" header, and so it should be parsed
differently. You will run into the same problem if you try to call
GetValues() on some other headers (like WWW-Authenticate, Authorization
etc).
If you are really interested in parsing the Set-Cookie header yourself, you
should use GetValue() method, and then parse the resultant string (which
will be the entire header value) yourself.
I am curious as to why you are doing this though. Have you looked at the
System.Net.Cookie, System.Net.CookieContainer, and
System.Net.CookieCollection classes ? If you set a CookieContainer on your
webrequest, it will make sure to parse the resultant "set-cookie" response
headers, and also to send the cookies when you send subsequent requests to
the same server/domain. You can also enumerate the cookies, and get the
name/values, expiry and other stuff. So, it will do the parsing for you.
--
Remove "user" from the email address to reply to the author.
This posting is provided "AS IS" with no warranties, and confers no rights
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Afanasiy" <abelikov72@hotmail.com> wrote in message
news:50i9109uhsofi6t49uvk9ril0thinfhg6v@4ax.com...
> On 25 Jan 2004 21:54:55 -0800, ferozed@microsoft.com (Feroze [MSFT])
> wrote:
>
> >Can you show me the input header string as well ?
>
> Server: Microsoft-IIS/5.0
> Date: Mon, 26 Jan 2004 07:52:38 GMT
> X-Powered-By: ASP.NET
> P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"
> Content-Length: 2628
> Content-Type: text/html
> Set-Cookie: SomethingOrOther=SID=3482742; expires=Sun, 25-Apr-2004
> 05:00:00 GMT; path=/,ASPSESSIONIDACTTBRRQ=HHFFHIAAPHFPHKDFGDPOPBLG; path=/
> Cache-control: private
>
> Of course, my usenet client has wrapped the Set-Cookie line.
> I assume you will be able to figure that out.
>
> >Also, what is the
> >type of the "response" object used in your code ?
>
> System.Net.WebResponse, as returned by System.Net.WebRequest's GetResponse
>
> >
> >> With code like this you will see the problem with header
> >> values which contain commas.
> >>
> >> foreach (string h in response.Headers.GetValues("Set-Cookie")) {
> >> Response.Write(h+"<hr>");
> >> }
> >
> >Is it of type System.Net.HttpWebResponse, or System.Web.HttpResponse ?
> >I need to know to find out where this behavior is occuring.
>
> System.Net.WebResponse
>
> >I will need these two pieces of information before we decide if this
> >is a bug.
>
> It has to be a bug. :p
>
> -AB
>