Solved

Sending custom Response Headers

Posted on 2001-06-28
11
274 Views
Last Modified: 2008-02-01
I need to send the following response from my ASP page:

HTTP/1.0 302 Redirection
Set-Cookie: WebMailID=3B3B7624; Path=/
Cache-control: no-cache="set-cookie"
Cache-control: private
Content-Length: 0
Location: http://www.sm.gordon.edu/MBX/garth/ID=3B3B7625

I don't want the server to send anyting else.  I've got the whole thing in one string and the lines are separated by Chr(10)'s.
0
Comment
Question by:garthmiller
  • 6
  • 5
11 Comments
 
LVL 7

Expert Comment

by:John844
ID: 6235518
are you using

Response.AddHeader

show the code..
0
 

Author Comment

by:garthmiller
ID: 6235540
I don't know what I should use.  I went through a lot of code to get this string back from another server.

<%
'Lots of code here

strREDIRECT = socket.Buffer
%>

After this strREDIRECT contains all of the lines I listed before.
0
 
LVL 7

Expert Comment

by:John844
ID: 6235562
here are a few ideas if you are not using them  
you might be able to use response.redirect as well


<%@ Language=VBScript %>
<%
Response.Buffer = true
Response.Clear
Response.AddHeader "HTTP/1.0 302", "Redirection"
'Response.AddHeader "Set-Cookie: WebMailID=3B3B7624; Path=/
Response.Cookies("WebMailID") = "3B3B7624"
Response.CacheControl = "no-cache"
Response.AddHeader "cache-control","private"
Response.AddHeader "Content-Length", "0"
'Response.AddHeader "Cache-control": no-cache="set-cookie"
Response.AddHeader "Location", "http://www.sm.gordon.edu/MBX/garth/ID=3B3B7625"

Response.End
%>
0
 
LVL 7

Expert Comment

by:John844
ID: 6235571
dont understand the question.  you might want to rephrase it.  do you mean that you have the string of 6 items like
HTTP/1.0 302 Redirection<chr(10)>Set-Cookie: WebMailID=3B3B7624; Path=/<chr(10)>Cache-control: no-cache="set-cookie"<chr(10)>Cache-control: private
Content-Length: 0<chr(10)>Location: http://www.sm.gordon.edu/MBX/garth/ID=3B3B7625

seperated with chr(10) and you want to display them like

HTTP/1.0 302 Redirection
Set-Cookie: WebMailID=3B3B7624; Path=/
Cache-control: no-cache="set-cookie"
Cache-control: private
Content-Length: 0
Location: http://www.sm.gordon.edu/MBX/garth/ID=3B3B7625
0
 
LVL 7

Expert Comment

by:John844
ID: 6235580
if that is what you have, then use something like:

dim aryString
aryString = split(strREDIRECT,chr(10))

dim i
for i = lbound(aryString,1) to ubound(aryString,1)
  response.write aryString(i) & "<BR>" & vbCrLf
next
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:garthmiller
ID: 6235595
I have all the items in one long string like:

HTTP/1.0 302 Redirection<chr(10)>Set-Cookie: WebMailID=3B3B7624; Path=/<chr(10)>Cache-control: no-cache="set-cookie"<chr(10)>Cache-control:
private<chr(10)>Content-Length: 0<chr(10)>Location: http://www.sm.gordon.edu/MBX/garth/ID=3B3B7625
0
 
LVL 7

Expert Comment

by:John844
ID: 6235630
here, try this:

<%@ Language=VBScript %>
<%
dim strRedirect
strRedirect = "HTTP/1.0 302 Redirection" & chr(10) & "Set-Cookie: WebMailID=3B3B7624; Path=/" & chr(10) & "Cache-control: no-cache=""set-cookie""" & chr(10) & "Cache-control: private" & chr(10) & "Content-Length: 0" & chr(10) & "Location: http://www.sm.gordon.edu/MBX/garth/ID=3B3B7625"

dim aryString
aryString = split(strREDIRECT,chr(10))

dim i
for i = lbound(aryString,1) to ubound(aryString,1)
 response.write aryString(i) & "<BR>" & vbCrLf
next




%>
0
 

Author Comment

by:garthmiller
ID: 6235711
Ok, here is what I've got:

<%
     'Send Redirect response to client
     Response.Buffer = true
     Response.Clear          
     Response.AddHeader "HTTP/1.0 302", "Redirection"
     Response.AddHeader "Set-Cookie", "WebMailID=" & strWebMailID & "; Path=/"
     Response.AddHeader "Cache-control","no-cache=""set-cookie"""
     Response.AddHeader "Cache-control","private"
     Response.AddHeader "Content-Length", "0"
     Response.AddHeader "Location", strLocation
     Response.Flush
%>

I'm not sure if this is sending the right thing to my browser though.  Will it be redirected?  Will it have a cookie set for WebMailID?
0
 

Author Comment

by:garthmiller
ID: 6235776
After I execute the code above, I view the source in my browser and this is what I see:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD>
<BODY></BODY></HTML>

I don't want the server to send all this stuff!
0
 
LVL 7

Accepted Solution

by:
John844 earned 300 total points
ID: 6235885
you can try this:  I am assuming that the first item in list will be the http...redirection and the last item in list will be the location

<%@ Language=VBScript %>
<%
dim strRedirect
strRedirect = "HTTP/1.0 302 Redirection" & chr(10) & "Set-Cookie: WebMailID=3B3B7624; Path=/" & chr(10) & "Cache-control: no-cache=""set-cookie""" & chr(10) & "Cache-control: private" & chr(10) & "Content-Length: 0" & chr(10) & "Location: http://www.sm.gordon.edu/MBX/garth/ID=3B3B7625"

dim aryString
aryString = split(strREDIRECT,chr(10))
dim aryTemp

dim i
for i = lbound(aryString,1) to ubound(aryString,1)
     'response.write aryString(i) & "<BR>" & vbCrLf
     aryTemp = split(aryString(i),":")
     'ignore first and last because they have redirection in them
     if i = lbound(aryString,1) or i = ubound(aryString,1) then
     else
          if ubound(aryTemp,1) > 0 then
               'Response.Write aryTemp(0) & " ### " & aryTemp(1) & "<BR>"
               Response.AddHeader aryTemp(0),aryTemp(1)
          else
               'Response.Write aryTemp(0) & " ### " & "<BR>"
               Response.AddHeader aryTemp(0),""
          end if
     end if
next
'Response.write "redirect to " & mid(aryString(ubound(aryString,1)),11)
Response.redirect mid(aryString(ubound(aryString,1)),11)


%>
0
 

Author Comment

by:garthmiller
ID: 6237979
Great answer. Thank you very much!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now