Re: Writing cookies from include file
Brian Burgess wrote:[color=blue]
> Hi Michael,
> So what if then page1.asp Server.Executes page2.asp in a loop. And
> the cookies are then set in page2.asp .. should the cookies not then
> write?[/color]
The cookies aren't available until
- they are sent to the browser as part of a Response AND
- the browser sends a new Request.
Here's an example of how cookies work:
0. Browser and server establish a connection,
1. Browser sends request to server,
2. Server ASP code stores cookie in Response object,
3. Server sends contents of response object to browser,
4. Browser accepts response contents and stores cookie,
5. Browser and server close connection.
Only now is the cookie is available for any *subsequent* HTTP requests.
What you are trying to do (but which won't work):
0. Browser and server establish a connection,
1. Browser sends request to server,
2. Server ASP code stores cookie in *Response* object,
3. Server ASP code tries to read same cookie from *Request* object, but
it isn't there!
....
Writing a cookie to the Response object does not mean that it is
available immediately (in the same script) from the *Request* object.
Also note that Server.Execute does not establish a new connection; it
uses the same connection as the calling script.
If you want to pass variables from one script to the other, then use
Session or Application variables.
Good Luck,
Michael D. Kersey
[color=blue]
> On Fri, 12 Sep 2003 03:52:45 -0500, "Michael D. Kersey"
> <mdkersey@hal-pc.org> wrote:
>[color=green]
> >Brian Burgess wrote:[color=darkred]
> >> So I can do:
> >> <%
> >> Response.Cookie s("cookie1") = "blah"
> >> Response.Cookie s("cookie1").Ex pires=DateAdd(" n", 15, Now)[/color]
> >
> >This code builds a cookie in the Response object, but it does not send
> >the cookie to the browser yet. The cookie (which is an HTTP "Set-Cookie"
> >header) will be sent to the browser after the script terminates.
> >[color=darkred]
> >> Server.Execute( "page2.asp" )
> >> ..
> >> %>
> >>
> >> Then in page2.asp I can do something like:
> >> <%
> >> Dim strCookie1
> >> strCookie1 = Request.Cookies ("cookie1")
> >> %>[/color]
> >
> >Since the cookie has not yet been sent to the browser, the Request
> >object will not be able to fetch that cookie. Only after your script
> >terminates will the cookie be sent.
> >
> >Good Luck,
> >Michael D. Kersey[/color][/color]
Brian Burgess wrote:[color=blue]
> Hi Michael,
> So what if then page1.asp Server.Executes page2.asp in a loop. And
> the cookies are then set in page2.asp .. should the cookies not then
> write?[/color]
The cookies aren't available until
- they are sent to the browser as part of a Response AND
- the browser sends a new Request.
Here's an example of how cookies work:
0. Browser and server establish a connection,
1. Browser sends request to server,
2. Server ASP code stores cookie in Response object,
3. Server sends contents of response object to browser,
4. Browser accepts response contents and stores cookie,
5. Browser and server close connection.
Only now is the cookie is available for any *subsequent* HTTP requests.
What you are trying to do (but which won't work):
0. Browser and server establish a connection,
1. Browser sends request to server,
2. Server ASP code stores cookie in *Response* object,
3. Server ASP code tries to read same cookie from *Request* object, but
it isn't there!
....
Writing a cookie to the Response object does not mean that it is
available immediately (in the same script) from the *Request* object.
Also note that Server.Execute does not establish a new connection; it
uses the same connection as the calling script.
If you want to pass variables from one script to the other, then use
Session or Application variables.
Good Luck,
Michael D. Kersey
[color=blue]
> On Fri, 12 Sep 2003 03:52:45 -0500, "Michael D. Kersey"
> <mdkersey@hal-pc.org> wrote:
>[color=green]
> >Brian Burgess wrote:[color=darkred]
> >> So I can do:
> >> <%
> >> Response.Cookie s("cookie1") = "blah"
> >> Response.Cookie s("cookie1").Ex pires=DateAdd(" n", 15, Now)[/color]
> >
> >This code builds a cookie in the Response object, but it does not send
> >the cookie to the browser yet. The cookie (which is an HTTP "Set-Cookie"
> >header) will be sent to the browser after the script terminates.
> >[color=darkred]
> >> Server.Execute( "page2.asp" )
> >> ..
> >> %>
> >>
> >> Then in page2.asp I can do something like:
> >> <%
> >> Dim strCookie1
> >> strCookie1 = Request.Cookies ("cookie1")
> >> %>[/color]
> >
> >Since the cookie has not yet been sent to the browser, the Request
> >object will not be able to fetch that cookie. Only after your script
> >terminates will the cookie be sent.
> >
> >Good Luck,
> >Michael D. Kersey[/color][/color]
Comment