来源:http://blog.sina.com.cn/s/blog_5499a1eb010005x1.html
1、遍历web服务器变量集合
int loop1, loop2;
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Key: " + arr1[loop1] + "<br>");
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>");
}
}
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Key: " + arr1[loop1] + "<br>");
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>");
}
}
2、遍历结果
Key: ALL_HTTP
Value 0: HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:zh-cn HTTP_HOST:192.168.0.240 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Alexa Toolbar) HTTP_UA_CPU:x86 HTTP_X_REWRITE_URL:/Test/Test_NameValue.aspx
Key: ALL_RAW
Value 0: Connection: Keep-Alive Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */* Accept-Encoding: gzip, deflate Accept-Language: zh-cn Host: 192.168.0.240 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Alexa Toolbar) UA-CPU: x86 X-Rewrite-URL: /Test/Test_NameValue.aspx
Key: APPL_MD_PATH
Value 0: /LM/W3SVC/545384892/Root
Key: APPL_PHYSICAL_PATH
Value 0: D:/work/woall_last/
Key: AUTH_TYPE
Value 0:
Key: AUTH_USER
Value 0:
Key: AUTH_PASSWORD
Value 0:
Key: LOGON_USER
Value 0:
Key: REMOTE_USER
Value 0:
Key: CERT_COOKIE
Value 0:
Key: CERT_FLAGS
Value 0:
Key: CERT_ISSUER
Value 0:
Key: CERT_KEYSIZE
Value 0:
Key: CERT_SECRETKEYSIZE
Value 0:
Key: CERT_SERIALNUMBER
Value 0:
Key: CERT_SERVER_ISSUER
Value 0:
Key: CERT_SERVER_SUBJECT
Value 0:
Key: CERT_SUBJECT
Value 0:
Key: CONTENT_LENGTH
Value 0: 0
Key: CONTENT_TYPE
Value 0:
Key: GATEWAY_INTERFACE
Value 0: CGI/1.1
Key: HTTPS
Value 0: off
Key: HTTPS_KEYSIZE
Value 0:
Key: HTTPS_SECRETKEYSIZE
Value 0:
Key: HTTPS_SERVER_ISSUER
Value 0:
Key: HTTPS_SERVER_SUBJECT
Value 0:
Key: INSTANCE_ID
Value 0: 545384892
Key: INSTANCE_META_PATH
Value 0: /LM/W3SVC/545384892
Key: LOCAL_ADDR
Value 0: 192.168.0.240
Key: PATH_INFO
Value 0: /Test/Test_NameValue.aspx
Key: PATH_TRANSLATED
Value 0: D:/work/woall_last/Test/Test_NameValue.aspx
Key: QUERY_STRING
Value 0:
Key: REMOTE_ADDR
Value 0: 192.168.0.240
Key: REMOTE_HOST
Value 0: 192.168.0.240
Key: REMOTE_PORT
Value 0: 1265
Key: REQUEST_METHOD
Value 0: GET
Key: SCRIPT_NAME
Value 0: /Test/Test_NameValue.aspx
Key: SERVER_NAME
Value 0: 192.168.0.240
Key: SERVER_PORT
Value 0: 80
Key: SERVER_PORT_SECURE
Value 0: 0
Key: SERVER_PROTOCOL
Value 0: HTTP/1.1
Key: SERVER_SOFTWARE
Value 0: Microsoft-IIS/6.0
Key: URL
Value 0: /Test/Test_NameValue.aspx
Key: HTTP_CONNECTION
Value 0: Keep-Alive
Key: HTTP_ACCEPT
Value 0: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Key: HTTP_ACCEPT_ENCODING
Value 0: gzip, deflate
Key: HTTP_ACCEPT_LANGUAGE
Value 0: zh-cn
Key: HTTP_HOST
Value 0: 192.168.0.240
Key: HTTP_USER_AGENT
Value 0: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Alexa Toolbar)
Key: HTTP_UA_CPU
Value 0: x86
Key: HTTP_X_REWRITE_URL
Value 0: /Test/Test_NameValue.aspx
Value 0: HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:zh-cn HTTP_HOST:192.168.0.240 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Alexa Toolbar) HTTP_UA_CPU:x86 HTTP_X_REWRITE_URL:/Test/Test_NameValue.aspx
Key: ALL_RAW
Value 0: Connection: Keep-Alive Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */* Accept-Encoding: gzip, deflate Accept-Language: zh-cn Host: 192.168.0.240 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Alexa Toolbar) UA-CPU: x86 X-Rewrite-URL: /Test/Test_NameValue.aspx
Key: APPL_MD_PATH
Value 0: /LM/W3SVC/545384892/Root
Key: APPL_PHYSICAL_PATH
Value 0: D:/work/woall_last/
Key: AUTH_TYPE
Value 0:
Key: AUTH_USER
Value 0:
Key: AUTH_PASSWORD
Value 0:
Key: LOGON_USER
Value 0:
Key: REMOTE_USER
Value 0:
Key: CERT_COOKIE
Value 0:
Key: CERT_FLAGS
Value 0:
Key: CERT_ISSUER
Value 0:
Key: CERT_KEYSIZE
Value 0:
Key: CERT_SECRETKEYSIZE
Value 0:
Key: CERT_SERIALNUMBER
Value 0:
Key: CERT_SERVER_ISSUER
Value 0:
Key: CERT_SERVER_SUBJECT
Value 0:
Key: CERT_SUBJECT
Value 0:
Key: CONTENT_LENGTH
Value 0: 0
Key: CONTENT_TYPE
Value 0:
Key: GATEWAY_INTERFACE
Value 0: CGI/1.1
Key: HTTPS
Value 0: off
Key: HTTPS_KEYSIZE
Value 0:
Key: HTTPS_SECRETKEYSIZE
Value 0:
Key: HTTPS_SERVER_ISSUER
Value 0:
Key: HTTPS_SERVER_SUBJECT
Value 0:
Key: INSTANCE_ID
Value 0: 545384892
Key: INSTANCE_META_PATH
Value 0: /LM/W3SVC/545384892
Key: LOCAL_ADDR
Value 0: 192.168.0.240
Key: PATH_INFO
Value 0: /Test/Test_NameValue.aspx
Key: PATH_TRANSLATED
Value 0: D:/work/woall_last/Test/Test_NameValue.aspx
Key: QUERY_STRING
Value 0:
Key: REMOTE_ADDR
Value 0: 192.168.0.240
Key: REMOTE_HOST
Value 0: 192.168.0.240
Key: REMOTE_PORT
Value 0: 1265
Key: REQUEST_METHOD
Value 0: GET
Key: SCRIPT_NAME
Value 0: /Test/Test_NameValue.aspx
Key: SERVER_NAME
Value 0: 192.168.0.240
Key: SERVER_PORT
Value 0: 80
Key: SERVER_PORT_SECURE
Value 0: 0
Key: SERVER_PROTOCOL
Value 0: HTTP/1.1
Key: SERVER_SOFTWARE
Value 0: Microsoft-IIS/6.0
Key: URL
Value 0: /Test/Test_NameValue.aspx
Key: HTTP_CONNECTION
Value 0: Keep-Alive
Key: HTTP_ACCEPT
Value 0: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Key: HTTP_ACCEPT_ENCODING
Value 0: gzip, deflate
Key: HTTP_ACCEPT_LANGUAGE
Value 0: zh-cn
Key: HTTP_HOST
Value 0: 192.168.0.240
Key: HTTP_USER_AGENT
Value 0: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Alexa Toolbar)
Key: HTTP_UA_CPU
Value 0: x86
Key: HTTP_X_REWRITE_URL
Value 0: /Test/Test_NameValue.aspx
164

被折叠的 条评论
为什么被折叠?



