Scott Hanselman

NuGet Package of the Week #5 - Debugging ASP.NET MVC applications with Glimpse

April 19, '11 Comments [19] Posted in ASP.NET | ASP.NET MVC | NuGet | NuGetPOW
Sponsored By

Hey, have you implemented the NuGet Action Plan? Get on it, it'll take only 5 minutes: NuGet Action Plan - Upgrade to 1.2, Setup Automatic Updates, Get NuGet Package Explorer. NuGet 1.2 is out, so make sure you're set to automatically update!

The Backstory: I was thinking since the NuGet .NET package management site is starting to fill up that I should start looking for gems (no pun intended) in there. You know, really useful stuff that folks might otherwise not find. I'll look for mostly open source projects, ones I think are really useful. I'll look at how they built their NuGet packages, if there's anything interesting about the way the designed the out of the box experience (and anything they could do to make it better) as well as what the package itself does.

A Client Side Glimpse into your Server

Glimpse is like the FireBug client side debugger, except it's implemented in JavaScript on the client side with hooks in to ASP.NET on the Server Side.


Glimpse includes not only better Route Debugging support than Phil Haack's original Route Debugger, but also excellent support for the little used but totally useful Trace.Write().

Let's just see it in action. You can do this with me now, in less than 5 minutes.

From a new ASP.NET MVC application (Or WebForms, for that matter), install Glimpse.

Add Library Package Reference

Before I run my app, I'm going to sprinkle in some Trace.Write and Trace.TraceError just to make the point.

public ActionResult Index()
ViewBag.Message = "Welcome to ASP.NET MVC!";
Trace.Write("Hey, this is nice");
Trace.TraceWarning("Oh, this could be bad.");
return View();

public ActionResult About()
Trace.TraceError("Oh, no! That's bad");
return View();

Now, I'll run my app. I can turn Glimpse on with a Bookmarklet, but I like visiting http://localhost:portname/Glimpse/Config and pressing the big "Turn Glimpse On" button. I'll drag the bookmarklet onto my toolbar one day.


Glimpse Config

Next, when I visit my site, notice the Glimpse control panel at the bottom! Insane. It's NOT a browser plugin, Dear Reader, that's all JavaScript.

Gimpse DIV up on the default ASP.NET MVC page

*Mind blown* see my Server-side Trace information in the Trace tab?  Isn't that nicer than Trace.axd?

If I switch to the Routes tab, I can see which Route matched my /Home/About request.

Using Glimpse to Debug Routes

Here's the Execution tab of Glimpse. I can see the methods that were executed, including those that weren't. Insane.

The Execution Tab of Glimpse

Glimpse, along with ELMAH,  is officially my favorite add-on to ASP.NET MVC. I'll be using it every day and I recommend you do as well.

I'm only touching the surface of what Glimpse can do, but I'll leave that extended tour their great site at


About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Wednesday, 20 April 2011 00:04:08 UTC
Scott, thank you for yet another little slice of awesome. My chocolatey goodness meter has actually just become self aware.
Wednesday, 20 April 2011 06:35:01 UTC
How do I secure the Gravitar content so it's available to any admin user on my site, but can't be enabled by the casual passer-by or the hacker intent on inflicting pain on my server?
Wednesday, 20 April 2011 06:36:35 UTC
... that'll learn me from hitting send so fast. The question has nothing to do with gravitar, but rather with Glimpse. A corrected comment:

How do I secure the Glimpse content so it's available to any admin user on my site, but can't be enabled by the casual passer-by or the hacker intent on inflicting pain on my server?
Wednesday, 20 April 2011 07:15:34 UTC
I agree with Brian, this looks pretty awesome; thanks for pointing this one out.
Wednesday, 20 April 2011 08:27:16 UTC
@ BrianHartung

How did you get your meter to become self aware, mine talks back to me and swears a lot, much like my other half (which I put down to lack-of-coffee-coding-practices).

Thanks Scott, this will be very useful (I am assuming it works with all flavours of ASP.NET?)

Wednesday, 20 April 2011 10:11:43 UTC
RE security... Currently you can turn glimpse on or off. Hence in a production scenario its not something that you would forced to have on all the time. Secondly, built into the system at the moment is the ability to filter by IP addresses - not that IP filtering is totally fool proof but it was easy to implement. Lastly, even though its not really security related but more just for clarity, you need to have the cookie present to see any data, hence casual users wouldn't be seeing your data.

Beyond this we have plans for a pluggable security pipeline. We thought about doing more out of the box, but there are just so many different ways we could go, we plans to do the following. The idea would be using MEF (thanks @gblock) you would simply implement a basic glimpse security interface (i.e. has 1 method like bool CanAccessGlimpse();), add the appropriate export that attribute and from that point you would be able to have what ever logic you wanted (i.e. only people who are logged in and are in the developer group can access glimpse).

We don't yet have a time frame on this as its not really a feature people have been asking for short term. But if this is something that you think is required please give us feedback.

Cheers Anthony
Wednesday, 20 April 2011 13:17:59 UTC
I wish it had existed when I was doing some MVC. And now that it exists, I wish I was doing some MVC...
Wednesday, 27 April 2011 19:51:57 UTC
This is sweet! Thanks
Friday, 20 May 2011 17:29:20 UTC
I think it is worth mentioning that glimpse requires jquery to be included in your page. There is nothing about that in the documentation.
Tuesday, 24 May 2011 18:16:55 UTC
@adam The dependency that Glimpse has on jQuery has been fixed and wont be an issue come release 0.82. It was never fully documented because we didn't want people to have to worry about it. But now, if you don't use jQuery or you are using a newer/older version of jQuery to what we have built on its not an issue. It will work seamlessly.
Wednesday, 25 May 2011 16:30:54 UTC
Its a great featured tool !
Ananth Ramsamy Meenachi
Wednesday, 08 June 2011 16:15:26 UTC
Looks like a great addition for development.

It's probably something that I'd like in a development environment but not perhaps being published to a production server(Security).

If i just didn't deploy the glimpse dlls in production do you see this causing any problems? Are there any hooks in code etc which might break?
Thursday, 16 June 2011 19:17:08 UTC
Nope, they won't be loaded. You'll want to remove them from production web.config though.
Tuesday, 05 July 2011 01:04:03 UTC
You really should mention you need to Install-Package Glimpse.Mvc3 to see the Route and other mvc related tabs. Took me 10 minutes to figure out what was going on :)
Tuesday, 06 September 2011 17:41:33 UTC
I ran into an issue installing Glimpse 0.85:

Successfully installed 'Glimpse 0.85'.
Successfully uninstalled 'Glimpse 0.85'.
Install failed. Rolling back...
Install-Package : Unable to find assembly references that are compatible with the target framework '.NETFramework,Version=v3.5'.
At line:1 char:16
+ Install-Package <<<< Glimpse

Do I have to be running .NET 4.0 to run Glimpse? Seems odd that I would need that.
Justin Collum
Tuesday, 06 September 2011 17:56:33 UTC
Ah, I see now: Glimpse only works with .NET 4.0.
Justin Collum
Tuesday, 04 October 2011 12:10:12 UTC
If I already use, let's say, NLog for logging, do I need to duplicate the trace calls?

I haven't looked at the Glimpse code, but is it extensible so that a NLog target can be developed?
Tuesday, 15 November 2011 08:47:26 UTC
It is very useful to us.
Thursday, 01 December 2011 17:06:04 UTC
Scott, gotta say this saved me from going crazy when I was trying to debug my custom route entries. You just earned 1000 brownie points in my diary :)
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.