Retrieving values of all server environment variables

Posted by in ASP.NET category on for Intermediate level | Views : 8939 red flag

To list values of all sever environment variables in one go.

To list all sever environment variables in one go. Most of the times we will be looking to list server variables like REMOTE_ADDR, ALL_RAW,SCRIPT_NAME,HOST_NAME.. so here is a way to list all existing sever variables in a table format.

    <div style="font-family:Times New Roman;font-size:smaller;">

<table width="70%" align="center">
<tr bgcolor="#e6f1fb">
<td width="25%" align="center">
<td width="75%">
<% foreach(string Item in Request.ServerVariables){ %>
<td width="25%">
<%= Item %>
<td width="75%">
<% } %>

Here we are looping through Request.ServerVariables collection using foreach statement and displaying the name of the ServerVariable(by <%= Item %>) and value of that variable by using Request.ServerVariables["REMOTE_ADDR"]. Screen shot of output is shown in figure below.


By this we can list values of all sever variables.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Anil Kumar Reddy Perugu
Member Level: Starter
Member Status: Member
Member Since: 4/27/2008 10:49:55 PM

Login to vote for this post.

Comments or Responses

Posted by: Patel28rajendra on: 3/14/2012 | Points: 25

Its nice short but sweet


Rajendra Patel

Login to post response

Comment using Facebook(Author doesn't get notification)