having trouble reading header values in classic ASP

放肆的年华 提交于 2020-12-25 02:40:49

问题


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?


回答1:


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.




回答2:


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




回答3:


There is a better way than parsing each item yourself. Look at the values in Request.ServerVariables("ALL_HTTP") and find the header you need but named a bit different.

All HTTP headers start with HTTP_. I was looking for If-None-Match and it was in the collection as HTTP_IF_NONE_MATCH. To get the value I used Request.ServerVariables("HTTP_IF_NONE_MATCH").



来源:https://stackoverflow.com/questions/4371516/having-trouble-reading-header-values-in-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!