Turning on Tracing in MVC (and Web Forms)

To turn on tracing in MVC or Web Forms Web Sites is very simple. Add this trace element to the XML in the Web.config at the root of the web site:

        <trace enabled="true" pageOutput="false"
             requestLimit="40" localOnly="true"/>

Then in your browser, browse to the root of the web site in IISExpress or full IIS, and add trace.axd. For example, if you site is at http://localhost:51500, then browse to http://localhost:51500/trace.axd. There is an enormous amount of information that will help debug information about your web site there.

The localOnly="true" attribute tells it to only perform tracing when browsing from localhost. In production, it should not perform tracing. There is a huge amount of information that hackers would like to get in the trace info, including information from recent hits to the web site from people other than yourself.

A couple of warnings: make sure you are messing with the Web.config in the root of the site. I spent an hour wondering why it wasn't working, then realized I was messing with the wrong Web.config! Doh! In MVC, don't mess with the normal routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); that you put into route configuration at the top of the site. You need that. If that isn't there, MVC tries to handle the request for the .axd file and IIS (which performs the tracing) won't.

No comments :

Post a Comment