Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Sending custom Response Headers

Posted on 2001-06-28
11
279 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP CDO - Limiting Connections 3 59
Select only the top record in a left join 13 45
Index on a Table 6 25
MS SQL 2008 and stored prodcures and dates 5 13
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

837 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