Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

having trouble reading header values in classic ASP

This is all internal servers and software, so I'm very limited on my options, but this is where I'm at. This is already a band-aid to a workaround but I have no choice, so I'm just trying to make it work.

I have a simple .asp file on my server that is protected by a service that will handle the user authentication (I have no control over this service). When a user goes to this .asp file, it requires them to authenticate via the service, and the service then redirects them to the .asp.

The service is inserting custom values in to the http header that allow me to identify who has logged in (I need it further down the line). When I use the asp to view the ALL_RAW and ALL_HTTP values from the header, I can see all the custom values. But when I try to call these values specifically I get nothing.

I ran this simple loop:

<%
for each x in Request.ServerVariables
  response.write("<B>" & x & ":</b> " & Request.ServerVariables(x) & "<p />")
next
%>

and all the keys display including the custom ones. But none of the custom values will. The values are the part I need.

the only thing I can find unique about the custom values is that they look slightly different in the ALL_RAW value, but they all look correct in the ALL_HTTP. As best I can tell, they are formatted correctly. the only formatting differences between the standard and custom values are case and underscores instead of hyphens.

Why can I not read these custom values?

like image 836
MitchelWB Avatar asked Dec 06 '10 22:12

MitchelWB


2 Answers

I found my answer.

When I ran this loop

<%
for each x in Request.ServerVariables
  response.write("<B>" & x & ":</b> " & Request.ServerVariables(x) & "<p />")
next
%>

it would return a list of all the names that were in the header and their values. The custom value I was looking for would show as name "HTTP_CUSTOM_ID" and I could see it, with it's value in the ALL_HTTP and ALL_RAW, but when I tried to pull that specific value, it would return an empty string. The solution I stumbled on (by talking to someone else here at work who had gone through a similar situation with the same service I was trying to accommodate is to use:

<%=Request.ServerVariables("HEADER_CUSTOM_ID")%>

When viewing the full header, nothing led me to use the HEADER prefix instead of the HTTP, in fact, it led me opposite. And I never found any mention of this anywhere searching online either. So I'm posting my own answer to my question here so it is on the web.

like image 192
MitchelWB Avatar answered Sep 22 '22 23:09

MitchelWB


For the sake of expedience, why not just parse Request.ServerVariables("ALL_RAW") yourself?

like image 32
Joel Spolsky Avatar answered Sep 21 '22 23:09

Joel Spolsky