CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Rod Paddock


Simple ServerVariables Code (Updated)

I don't know how many times I have written the code to show the contents of the Request.ServerVariables collection sent to an ASP.NET page. So I'm gonna blog it to make sure I always have the code:

Response.Write("<TABLE BORDER='2'>")

For lnKount As Integer = 0 To Request.ServerVariables.Count - 1

   Response.Write("<TR>")

   Response.Write("<TD>")

   Response.Write(Request.ServerVariables.Keys(lnKount))

   Response.Write("</TD>")

   Response.Write("<TD>")

   Response.Write(Request.ServerVariables.Item(lnKount))

   Response.Write("</TD>")

   Response.Write("</TR>")

Next

Response.Write("</TABLE>")

UPDATE:

From a comment posted here I learned something new. In ASP.NET 2.0 add the trace attribute to your web page directive:

<%@ Page Language="VB" Trace="true" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

You can also add an element to your web.config file to enable tracing on a web site level.

<trace enabled="true" pageOutput="true"/>

Adding this attribute returns a ton of debugging and performance for your web page(s). This is a very cool setting. Reminds me of my Cold Fusion days.

 



Comments

daughtkom said:

I can't count the number of times I've typed that in classic ASP.  

In ASP.NET, why would you personally choose to do this instead of setting trace="true" in the page directive?
# June 9, 2006 4:00 PM

Rod Paddock [MVP] said:

Good point daughtcom. I didn't know about that setting. I updated the blog post. Thanks!
# June 9, 2006 5:28 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors