Retrieving values of all server environment variables

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

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

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">
ServerVariable:
</td>
<td width="75%">
Value
</td>
</tr>
<% foreach(string Item in Request.ServerVariables){ %>
<tr>
<td width="25%">
<%= Item %>
</td>
<td width="75%">
<%=Request.ServerVariables[Item]%>
</td>
</tr>
<% } %>
</table>
</div>


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.





Conclusion


By this we can list values of all sever variables.

Enjoy...
Page copy protected against web site content infringement by Copyscape

About the Author

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

http://anil.myfunda.net

Login to vote for this post.

Comments or Responses

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

Its nice short but sweet

Thanks

Rajendra Patel

Login to post response

Comment using Facebook(Author doesn't get notification)