ASP中Request ServerVariables,Server_Name,Http_Host之间的区别

在ASP中,Request.ServerVariables("Server_Name")与Request.ServerVariables("Http_Host")之间有什么区别呢?
如果不仔细看,您应该看不出它们之间的区别。在网上搜了很多,还是也没有看懂,不过最后还是有一句话很是明白:
Request.ServerVariables("Http_Host")可以得到非80的Server_Port端口
比如请求的地址是http://www.doman.com:8000/index.asp,则:
Request.ServerVariables("Http_Host")得到的是www.doman.com:8000
Request.ServerVariables("Server_Name")得到的是www.doman.com
简单地说就是,Http_Host=Server_Name:Server_Port。
我们可以利用Http_Referer和Server_Name写一个ASP防止外部提交的函数
function ChkPost()
dim server_v1,server_v2
chkpost=false
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
If Mid(server_v1,8,Len(server_v2))<>server_v2 then
chkpost=False
else
chkpost=True
end If
end function

不过这个函数不能保证完全准确,因为它不能校验端口是否一致,并且在HTTP协议不一致的时候会产生错误结果,于是可以看下这段ASP防止外部提交的代码,你可能会倾向于使用这个:
dim s1 : s1=Request.ServerVariables("HTTP_REFERER")
if isnull(s1) or s1="" then
response.end
else
s1=lcase(s1)
end if
dim s2 : s2=Request.ServerVariables("HTTP_HOST")
if isnull(s2) or s2="" then
response.end
else
s2=lcase(s2)
end if
s1=split(s1,"://")(1)
if left(s1,len(s2))<>s2 then response.end

另附未经证实的解释,仅供参考:

在Windows2000下

SERVER_NAME等于HTTP_HOST

在Windows2003下
>> 下面的*号为Request.ServerVariables("APPL_MD_PATH") 请求的 /LM/W3SVC/*/ROOT
当在 CMD 下运行"CScript adsutil.vbs Set w3svc/*/UseHostName true"时
SERVER_NAME为Windows的计算机名
当在 CMD 下运行"CScript adsutil.vbs Set w3svc/*/UseHostName flase"时
SERVER_NAME等于HTTP_HOST