Re: Request Cookies right after they're being Set
From: Joerg Jooss (joerg.jooss_at_gmx.net)
Date: 09/09/04
- Next message: Piotr Wójcicki: "Re: email attachment from string"
- Previous message: olivogt: "Re: SQL Server does not exist or access denied"
- In reply to: CDARS: "Re: Request Cookies right after they're being Set"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 9 Sep 2004 12:58:29 +0200
CDARS wrote:
> Dear all,
>
> So I understand that when I call
>
>> response.cookies("test") = now
>
> the response object is updated. BUT NOT the request object.
> I really really want to know:
>
> 1) Why it seems to me that in ASP3.0, when I update response object,
> the request object is updated automatically? As I said in the first
> post, a very similar ASP3.0 code will always print two different
> dates.
Don't assume that both frameworks use the same implementation. Granted, the
ASP.NET behaviour is outright bizarre.
> 2) Why for ASP.NET the FIRST post can give two different dates? If
> response and request objects are separated, I would expect two empty
> string from the 1st load...
OK, after digging through the implementation, here's the answer:
When accessing HttpRequest.Cookies for the first time, it actually copies
all cookies from HttpResponse.Cookies. I have no freaking clue what that is
good for (or is it just plain wrong?). It makes no sense to me at all.
Anyway, this it what happens:
Response.Cookies("test").Value = Now
' Creates a new cookie "test" with value DateTime.Now
Response.Write(Request.Cookies("test").Value)
' 1st request: Creates a new cookie collection for HttpRequest, and copies
all response
' cookies to it, prints out DateTime.Now
' 2nd+ request: Gets cookie "test" from request, prints out value stored in
cookie, which
' is DateTime plus 10 days
Response.Write("<hr>")
Response.Cookies("test").Value = Now.AddDays(10)
' Changes value for test cookie, which is contained in both collections
Response.Write(Request.Cookies("test").Value)
' Prints out prints out value stored in cookie "test", which
' is DateTime plus 10 days
> 3) I am actually re-writing a ASP3.0 web app with ASP.NET. The old
> code very often set cookies by response and get the value ALWAYS with
> Request in the same page (or even just in the next line). How should I
> put it in ASP.NET?
Don't create cookies in Response.Cookies before accessing Request.Cookies.
This will prevent this strange copying behaviour.
> 4) Any more funny changes on playing with ASP.NET Cookies?
Hopefully not...
Cheers,
-- Joerg Jooss joerg.jooss@gmx.net
- Next message: Piotr Wójcicki: "Re: email attachment from string"
- Previous message: olivogt: "Re: SQL Server does not exist or access denied"
- In reply to: CDARS: "Re: Request Cookies right after they're being Set"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|