Writing Cookies & Redirecting in same ASP script

Results 1 to 4 of 4

Thread: Writing Cookies & Redirecting in same ASP script

  1. #1
    ICornish Guest

    Default Writing Cookies & Redirecting in same ASP script

    I have a script which takes some input from a form and redirects to another page depending on that input. The script works fine. But I wanted to add the ability to "remember" some of the form input using a cookie. I&#039ve got a script to write the cookie and it works fine, but when I include it in the script with the redirection, it doesn&#039t write the script. My script does not have any HTML at all, it just looks at the data, then (hopefully) writes the cookie, then redirects.<BR><BR>I&#039ve tried putting in a Response.Flush, but I just get problems with "HTTP Headers already written..."

  2. #2
    Ben Timby Guest

    Default RE: Writing Cookies & Redirecting in same ASP scri

    is <BR>Response.Buffer = True<BR>the first line of the script? if not, that is probably the problem, cookies are sent in the HTTP header, so setting a cookie will cause the header to be sent to the browser, unless you are buffering the response.

  3. #3
    ICornish Guest

    Default RE: Writing Cookies & Redirecting in same ASP scri

    Yes, Response.Buffer is there. <BR><BR>Here&#039s my script:-<BR>&#060;%Response.Buffer=True%&#062;<BR>&#060;HT ML&#062;<BR>&#060;HEAD&#062;<BR>&#060;/HEAD&#062;<BR>&#060;BODY&#062;<BR><BR><BR>&#060;%< BR>&#039Translate the Affiliate name to Facility Code & Login code<BR><BR>&#039Write out a cookie for the User<BR>Response.Cookies("ACDB")("Affiliate")=Requ est("Affiliate")<BR>Response.Cookies("ACDB").Domai n="&#060;domain name&#062;"<BR>Response.Cookies("ACDB").Expires=Da te+365<BR>Response.Cookies("ACDB").secure=False<BR ><BR>Response.Flush<BR><BR>&#039Now direct the user to the right page.<BR><BR>Select Case Request("action")<BR> Case "Affiliate Data"<BR> Response.Redirect "AI.ASP?Facility=" & sFacility & "&Affiliate=" & Request("Affiliate")<BR> Case "Contacts"<BR> Response.Redirect "Contacts.ASP?Facility=" & sFacility & "&Affiliate=" & Request("Affiliate")<BR> Case Else<BR> Response.Redirect "main.asp"<BR>End Select<BR>%&#062;<BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;

  4. #4
    ICornish Guest

    Default RE: Writing Cookies & Redirecting - FIXED!

    That&#039ll teach me - I was developing on my test box, which is in a different domain to the production system, and I&#039d coded the cookie domain for the production system, and not the development system.<BR>It&#039s working now! I&#039m so happy!<BR><BR>Ic


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •