摘要:C# - HttpRequest ServerVariables 屬性
最近又因為專案的關係,需要以瀏覽器的資訊來當做唯一識別碼,之後請教了一下同事,在微軟 MSDN 中找到了這篇,感覺 HttpRequest ServerVariables 屬性還蠻實用的,特別將它收藏到Blog中...
Code:
using System.Collections.Specialized;
int loop1, loop2;
NameValueCollection collection;
collection = Request.ServerVariables;
String[] arrKey = collection.AllKeys;
for (loop1 = 0; loop1 < arr.Length; loop1++)
{
Response.Write("Key: " + arrKey[loop1] + "<br />");
String[] arrValues = collection.GetValues(arrKey[loop1]);
for (loop2 = 0; loop2 < arrValues.Length; loop2++)
{
Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arrValues[loop2]) + "<br />");
}
}
參考:
HttpRequest ServerVariables 屬性