NuGet Package of the Week #5 - Debugging ASP.NET MVC applications with Glimpse
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.
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.
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.
*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.
Here's the Execution tab of Glimpse. I can see the methods that were executed, including those that weren't. Insane.
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 http://www.getglimpse.com.
Enjoy.
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.
About Newsletter
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?
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?)
Adios!
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
I wish it had existed when I was doing some MVC. And now that it exists, I wish I was doing some MVC...
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?
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.
I haven't looked at the Glimpse code, but is it extensible so that a NLog target can be developed?
Comments are closed.