Company

Our Services

Our Clients

Articles

Names and Values of All Named ServerVariables

Published on: 30 August 2007 By: Ahsan Khan

This example returns a list of all the named ServerVariables and their values.

C#
int iKeys, iValues;
NameValueCollection nvCol;

nvCol = Request.ServerVariables;
String[] sarrAllKeys = nvCol.AllKeys;
for (iKeys = 0; iKeys < sarrAllKeys.Length; iKeys++)
{
Response.Write("Key: " + sarrAllKeys[iKeys]);
Response.Write("<br />");
String[] sarrValues = nvCol.GetValues(sarrAllkeys[iKey]);
for (iValues = 0; iValues < sarrValues.Length; iValues++)
{
Response.Write("Value " + iValues + ":" + Server.HtmlEncode(sarrValues[iValues]) + "<br />");
}
Response.Write("<br />");

}

VB
Dim intKeys As Integer
Dim intValues As Integer
Dim strLineBreak As String = "<br />"
Dim nvCol As NameValueCollection
Dim sarrKeys() as String
Dim sarrValues() as String

nvCol = Request.ServerVariables
sarrKeys = nvCol.AllKeys
For intKeys = 0 To sarrKeys.GetUpperBound(0)
Response.Write("Key: " & sarrKeys(intKeys))
Response.Write(strLineBreak)
sarrValues = nvCol.GetValues(intKeys)
For intValues = 0 To sarrValues.GetUpperBound(0)
Response.Write("Value " & intValues.ToString & ": " & Server.HtmlEncode(sarrValues(intValues)) & strLineBreak)
Next IntValues
Response.Write(strLineBreak)
Next intKeys

Links related to this article:
IIS/ASP.NET ServerVariables Collection List
Which Version of IIS/ASP is Running


underline

View All Articles (Articles Archive)

 

Chapter Zero Limited, 2 Providence Court, Pynes Hill, Exeter, UK, EX2 5JL
Tel: +44 (0)1392 361500, Fax: +44 (0)1392 361501