Iterating Through ServerVariables in ASP.Net and C#

ASP.NET Comments Off on Iterating Through ServerVariables in ASP.Net and C#

Sometimes you may need to verify all the servervariables to debug your code. Simply iterating through the servervariables collection can bring out the result. The following snippet is suffice to iterate.

code behind


protected void Page_Load(object sender, EventArgs e)
 {
 foreach (string x in Request.ServerVariables)
 {
 Label1.Text += x.ToString() + " : ";
 Label1.Text += Request.ServerVariables[x].ToString() + "<br/>";
 }
 }

.aspx file


<form id="form1" runat="server">
 <div>

<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

</div>
 </form>



Author

Search

Back to Top