获取所有命名的服务器变量的名称和值
1//下面的示例写出所有命名的服务器变量的名称和值。
2 int loop1, loop2;
3 NameValueCollection coll;
4
5 // Load ServerVariable collection into NameValueCollection object.
6 coll=Request.ServerVariables;
7 // Get names of all keys into a string array.
8 String[] arr1 = coll.AllKeys;
9 for (loop1 = 0; loop1 < arr1.Length; loop1++)
10 {
11 Response.Write("Key: " + arr1[loop1] + "<br>");
12 String[] arr2=coll.GetValues(arr1[loop1]);
13 for (loop2 = 0; loop2 < arr2.Length; loop2++)
14 {
15 Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>");
16 }
17 }
2 int loop1, loop2;
3 NameValueCollection coll;
4
5 // Load ServerVariable collection into NameValueCollection object.
6 coll=Request.ServerVariables;
7 // Get names of all keys into a string array.
8 String[] arr1 = coll.AllKeys;
9 for (loop1 = 0; loop1 < arr1.Length; loop1++)
10 {
11 Response.Write("Key: " + arr1[loop1] + "<br>");
12 String[] arr2=coll.GetValues(arr1[loop1]);
13 for (loop2 = 0; loop2 < arr2.Length; loop2++)
14 {
15 Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>");
16 }
17 }
显示结果如下:
Key: ALL_HTTP
Value 0: HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:zh-cn HTTP_COOKIE:ASP.NET_SessionId=udfdmq454mn2fa45q1aox255 HTTP_HOST:localhost HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322) HTTP_UA_CPU:x86
Key: ALL_RAW
Value 0: Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: zh-cn Cookie: ASP.NET_SessionId=udfdmq454mn2fa45q1aox255 Host: localhost User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322) UA-CPU: x86
Key: APPL_MD_PATH
Value 0: /LM/W3SVC/1/Root/ZOA/ZzbPublicGoods
Key: APPL_PHYSICAL_PATH
Value 0: D:\Project\ZOA\ZzbPublicGoods\
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: 1
Key: INSTANCE_META_PATH
Value 0: /LM/W3SVC/1
Key: LOCAL_ADDR
Value 0: 127.0.0.1
Key: PATH_INFO
Value 0: /ZOA/ZzbPublicGoods/WebForm1.aspx
Key: PATH_TRANSLATED
Value 0: D:\Project\ZOA\ZzbPublicGoods\WebForm1.aspx
Key: QUERY_STRING
Value 0:
Key: REMOTE_ADDR
Value 0: 127.0.0.1
Key: REMOTE_HOST
Value 0: 127.0.0.1
Key: REMOTE_PORT
Value 0: 1158
Key: REQUEST_METHOD
Value 0: GET
Key: SCRIPT_NAME
Value 0: /ZOA/ZzbPublicGoods/WebForm1.aspx
Key: SERVER_NAME
Value 0: localhost
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: /ZOA/ZzbPublicGoods/WebForm1.aspx
Key: HTTP_CONNECTION
Value 0: Keep-Alive
Key: HTTP_ACCEPT
Value 0: */*
Key: HTTP_ACCEPT_ENCODING
Value 0: gzip, deflate
Key: HTTP_ACCEPT_LANGUAGE
Value 0: zh-cn
Key: HTTP_COOKIE
Value 0: ASP.NET_SessionId=udfdmq454mn2fa45q1aox255
Key: HTTP_HOST
Value 0: localhost
Key: HTTP_USER_AGENT
Value 0: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)
Key: HTTP_UA_CPU
Value 0: x86