您的位置:首页 > 其它

显示所有命名的服务器变量的名称和值

2011-10-26 11:08 274 查看
下面的代码示例显示所有命名的服务器变量的名称和值。
using System.Collections.Specialized;

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 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐