Scott Hanselman

Hanselminutes Podcast 159 - IronPython in Action with Michael Foord

April 25, '09 Comments [5] Posted in DLR | Podcast | Python
Sponsored By

ironpythoninaction My one-hundred-and-fifty-ninth podcast is up. Michael Foord makes his living as a Python programmer. More specifically has an IronPython programmer. He chats with me about his company's use of IronPython, the DLR and why they picked Python over C# or VB.

40% OFF COUPON: Michael's hooked me up with a 40% off coupon for a limited time for Hanselminutes listeners. Just buy the book with coupon code "ironpython40".

Links from the Show

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is a sponsor for this show!

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET and Windows Forms. Enjoy the versatility of our new-generation Reporting Tool. Dive into our online community. Visit

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

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 SherWeb

ELMAH: Error Logging Modules and Handlers for ASP.NET (and MVC too!)

April 23, '09 Comments [29] Posted in ASP.NET | ASP.NET MVC | Bugs | NerdDinner | Open Source
Sponsored By

Joe Lowrance said, er tweeted, it best when he said,

"the amount of attention ELMAH hasn't got is shocking."

ELMAH is one of those largely unknown and deeply awesome .NET Open Source projects that should be part of ASP.NET proper.

What is ELMAH?

I like to say that ELMAH is Tivo for your ASP.NET Errors. You can get your Yellow Screens of Death, with full call-stack back and analyze what's really happening. It's Exception Driven Development. What's it really do?

Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilites without changing a single line of your code:

  • Logging of nearly all unhandled exceptions.
  • A web page to remotely view the entire log of recoded exceptions.
  • A web page to remotely view the full details of any one logged exception.
  • In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrors mode turned off.
  • An e-mail notification of each error at the time it occurs.
  • An RSS feed of the last 15 errors from the log.
  • A number of backing storage implementations for the log, including in-memory, Microsoft SQL Server and several contributed by the community.

Created by Atif Aziz (@raboof on Twitter) and Scott Mitchell, ELMAH means is "Error Logging Modules and Handlers" and has been rocking my world since, well, September of 2004.

(Small Correction, Scott Mitchell helped writing the original MSDN article. ELMAH is 100% conceived of by Atif.)

From the project site:

ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

ELMAH is wonderful for many reasons. First, because it just works. Second, because it's a fantastic example of effective use of HttpModules and HttpHandlers working together. Third, because it's been design with enough thought that nearly anything you'd want from it for use in a production site is there.

I'm sitting here in a cafe and I'm going to add ELMAH to the ASP.NET MVC-based Source Code. Actually, the site, as I don't need to recompile the source if I'm not doing anything tricky. ;)

Implementing ELMAH on your ASP.NET (MVC or otherwise) Site 

I download ELMAH, and I put its DLL in my /bin folder (or wherever you like to put libraries). ELMAH doesn't need to be referenced by your project directly if you don't want to. Ultimately it just needs to be in your bin folder so it can be found. You can put it in /lib and make a build event if you like, as long as it ends up in /bin.

Then I open up two instances of notepad and copy over a few HttpHandlers and HttpModules into my existing web.config. Tedious, but straightforward.

Where you put these depends on if you're using IIS6 or IIS7, but the general idea is the handlers looks like this:



and the modules looks like this:



You can pare it down a bit if you don't need ErrorMail, for example. Then, I hit my site at http://localhost:xxxx/elmah.axd and I get this Error log, similar to what you'd see via Trace.axd.

Error log for  on HANSELMAN-T60P (Page #1) - Windows Internet Explorer

Ok, no errors. Let's make some. I'll visit some messed up URLs and intentionally cause's what ELMAH says now:

Error log for  on HANSELMAN-T60P (Page #1) - Windows Internet Explorer (2)

And I can drill down and see the Yellow Screen of Death (YSOD) as it "would have been."

Error System.ArgumentException [5] - Windows Internet Explorer

Now, this assumes my ASP.NET MVC site has no error handling to speak of. ELMAH is watching for unhandled exceptions and recording them, holding them in memory. I can also setup logs to SQL Server or VistaDB or SQLLite so they'll live beyond application recycles.

You can certainly secure access to the ELMAH pages. You can also pull the errors into your favorite RSS Reader, which is a killer feature, IMHO.

Making ELMAH work with ASP.NET MVC's "HandleError" Attribute

In ASP.NET MVC there's an attribute called [HandleError] that will grab anything that goes wrong inside your controllers and show the ~\Shared\Error.aspx View. However, because it "handles" the error, it hides it from ELMAH. Remember that [HandleError] is a declarative try/catch. In my case, I want to have ELMAH handle it.

There's two ways around this.

One, I made a method in my Controller like this:

public ActionResult Trouble()
return View("Error");

In my web.config, I have a customErrors section like this:

This sends folks to /Dinners/Trouble which shows the Error page, after ELMAH takes care of it.

Second, as an advanced technique, I could write my own derived HandleErrorWithELMAHAttribute that logs the error using ELMAH's API, then passes the exception up to the default handler with ASP.NET MVC.

Looks like Dan Swatik's blog is dead. :( UPDATE: Looks like Dan Swatik was coincidentally doing a similar thing error this morning! What's nice about the solution on Dan's Blog, is that it was written with the help of Atif Aziz himself! (Remember, Atif's The primary author of ELMAH!) Here's the StackOverflow question.

My naive solution is below, but Atif's is better as it signals the error to ELMAH's pipeline rather that logging directly as mine does. Here's the more correct version:

namespace MvcDemo
using System;
using System.Web;
using System.Web.Mvc;
using Elmah;

public class HandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
public override void OnException(ExceptionContext context)

var e = context.Exception;
if (!context.ExceptionHandled // if unhandled, will be logged anyhow
|| RaiseErrorSignal(e) // prefer signaling, if possible
|| IsFiltered(context)) // filtered?


private static bool RaiseErrorSignal(Exception e)
var context = HttpContext.Current;
if (context == null)
return false;
var signal = ErrorSignal.FromContext(context);
if (signal == null)
return false;
signal.Raise(e, context);
return true;

private static bool IsFiltered(ExceptionContext context)
var config = context.HttpContext.GetSection("elmah/errorFilter")
as ErrorFilterConfiguration;

if (config == null)
return false;

var testContext = new ErrorFilterModule.AssertionHelperContext(
context.Exception, HttpContext.Current);

return config.Assertion.Test(testContext);

private static void LogException(Exception e)
var context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(e, context));

Below is my naive version.

I made this HandleErrorWithELMAHAttribute:

public class HandleErrorWithELMAHAttribute : HandleErrorAttribute
public override void OnException(ExceptionContext filterContext)
var context = HttpContext.Current;
Error error = new Error(filterContext.Exception, context);
ErrorLog log = ErrorLog.GetDefault(context);
string id = log.Log(error);
catch (Exception localException)
// IMPORTANT! We swallow any exception raised during the
// logging and send them out to the trace . The idea
// here is that logging of exceptions by itself should not
// be critical to the overall operation of the application.
// The bad thing is that we catch ANY kind of exception,
// even system ones and potentially let them slip by.



Then I put the attribute on my ASP.NET MVC Controller like this:

public class DinnersController : Controller {

Either way works, I actually kind of prefer the first one, although it requires a controller to have an essentially empty method to send folks to the shared error page. I keep the /Confused and /Trouble methods in there as I think it makes the site more personal.

Anyway, ELMAH rocks and you should use it today. Phil Haack loves ELMAH too! Jeff and the guys at StackOverflow use ELMAH also, albeit a "custom fork." (Release your code, Jeff!)

Time for me to to donate some money to the ELMAH Open Source efforts.


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 SherWeb

Paint Fence, Cut Wood, Pull Weed, Plant Tree - Finding Geek Balance Outside My Comfort Zone

April 23, '09 Comments [39] Posted in Musings | Personal
Sponsored By

Please forgive me this personal excursion. I had lunch with my friend Greg Hughes yesterday. It's nice when people know you well enough to really grok when something significant happens in your life. The opening part of the conversation at lunch, in person, went something like this

Greg: Hey, great to see you, what's up?

Me: D00d. I bought wood. Like, literally went to the, what's it called? The Lumberyard and purchased actual lumber. Like, trees. Then I cut them.

Greg: Holy crap. What brought this on?

...and the conversation continued in this general vein. He understood immediately. I'm finding balance by moving outside my comfort zone. I'm trying to become "handy" around the house. My previous handy experience was tiling my kitchen backsplash, and this required that I use actual lasers to succeed.

What you need to understand, Dear Reader, is how profoundly not-handy I am to appreciate what I'm trying to do here. My father and brother are handy. I am not. I am not handy in the way that short people are not tall. They aren't. It's just so.

I have never had a hobby that didn't involve computers. This is sad, I know.

I've talked before about how it's important as a Developer to Sharpen the Saw. This is an extension of this. Go outside your comfort zone. I

I try to travel a lot, meet different people, speak their language as a way of going outside my comfort zone. Of course, I speak about computers, so that kind of cancels that out, eh? ;)


When I speak to high-school students and local colleges, I tell them that I like software because of the intense sense of empowerment - the sense that I can do this - it can give you when creating. It seems silly and obvious, but I realize more now that other things can empower oneself. I intellectualized this long ago, but internalized it only recently.

Here's what I'm doing this year to push the envelope for me. This may not make me a better developer, but I hope it'll make me (and subsequently my kids) a better, more well-rounded person. Maybe that'll make me a better developer in some round-about way. I dunno, but I sure feel handy and empowered but in a new an different way.

Planting a Square Foot Garden

IMG_0136 One day, last week, it was sunny in Oregon. I looked at the strange yellow ball in the sky and grunted and then I went and bought lumber. I figured this is what people do when it's nice out. I've talked about a garden in the yard for years. This time, I made one.

I got 9 2x12's, and 3 4x4's. The first thing I learned was that 4x4s are in fact not four inches square. Turns out the whole inches thing is just a big lie in the wood world. This was news, but now I feel informed. :)

I ordered the dirt/compost, almost broke myself unloading two yards (not sure why it's called yards, but it was a trailer-load and a lot) and last night we planted our vegetables.

Being Handy Around the House

When I get in over my head with home improvements and things, I usually call my family or a handyman. I've stopped doing that, setup a toolbox and work area and started drilling holes in the wall. I've painted/stained 400 feet of fence, weeded until my hands hurt, and moved giant rocks, all in the last two weeks.

I'm starting to get ideas for other things I want to do around the house. Why, just today, I added two small towel holders in the upstairs bathroom. Changes the whole room, I say! And, as a plus, I did not electrocute myself.

Building an Arcade Console

IMG_0036I checked on Craigslist and found an ancient 1984 Video Trivia Arcade Console. With my friend John Batdorf we took it to the garage and gutted it. I'm putting a PC inside it, and maybe an Xbox and dubbing it the Hanselcade.

This is yet another project that I'd always meant to do, but hadn't because it seemed too large, too complex, too intense to attack. I can attach large, complex and intense computer problems, but this...this was physical.

But, I'd cut wood! I'd planted plants! I just did it. I took uncomfortable action and I started to make plans. What's nice about this project - all of these, in fact - is that they are large, but they can be broken up and aren't time-urgent.

It also kind of involved computers, indirectly, in that there's a computer inside. However, stuff like hooking up LEDs, buying resistors, drilling holes in steel and keeping the whole thing stock and clean - this is all outside my zone of comfort.

The Point

I'm learning, as I always am, but I'm exercising VERY different parts of my brain. I'm reminding myself of things I'd forgotten, and filling in gaps. I'm synthesizing bits of information that I'd thought unrelated into larger solutions. I'm getting a substantial and ongoing sense of satisfaction. I'm realizing that I can be good, well, adequate, at other things that aren't computers.

If there's something you've been meaning to do, especially if it's outside your expertise, go do it now. Pull a weed. Build a fort. Start a blog. Lift a weight. Maybe two.

This must be what having a hobby is like! Ah, to be well-rounded and balanced.

Related Posts

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 SherWeb

Social Networking for Developers - Conference Talk Video

April 21, '09 Comments [13] Posted in Back to Basics | Programming | Speaking
Sponsored By

UPDATE: Better quality videos from another conference were found and are up here.

First, a disclaimer. This is some really seriously guerilla video. Paul Mooney was kind enough to bust out his video camera and film my keynote at Devscovery in NYC this last Monday. (This was the same trip where I hung out at the Fog Creek offices and did a "Hanselminutes on Channel 9" video.)

Paul edited the video and put it up on Here's a link to the WMV file if you want to download it. You can also watch it embedded at Neuronspark. He put a lot of work into the editing, so thank you Paul for your community efforts!

I was a little silly so it was a lot more informal then most of my talks. I ran it like a classroom/university lecture with a lot of interactivity. Basically, the talk was loose, so be aware.

One of the things that I liked about this talk was that the talk was largely influenced by a StackOverflow question. The idea was to make a talk about Social Networking using a Social Networking site. I also think, that while the question isn't a programming-specific question, it's a good example of all things community (crowd-sourced)-related.

People voted on the best answer, some voted to shut down the question completely (!), comments broke out in the question and some answers, and the question was eventually turned into a "community wiki" question with collective ownership.

Here's a snapshot of the StackOverflow question (in case it's edited). Forgive the self-quoting:

How can social networking sites make you a better developer?

I am giving a keynote at Devscovery tomorrow at 9am. The title is "Social Networking for Developers." It's 90 minutes long and I don't want to waste anyone's time.

Everyone I talk to who uses Twitter, Blogs, StackOverflow, etc, says that these sites make them "better developers." However, few are able to qualify HOW and fewer will are able to quantify HOW MUCH better.

Is it just about getting answers to questions? Is it about the developer's third place?

Help me, O Stack Overflow, O great social network of developers, with my Keynote on Social Networking. ;)

What makes developers, usually an anti-social bunch, strive to use the internet for social purposes?

How do Social Networking sites help you better do your job?

And here's the answer with the most votes, from Rob P.:

  • Social Networks are loaded with people who will remind you not to wait until the night before a talk to ask such questions :)

But seriously, I think the biggest thing it does is remind people what a good developer can be. If you are someone who enjoys to go for a jog 2-3 times a week, you could very easily be the best runner you know. You might think that what you do is at or near the limit of what anyone could expect to do.

Until you go to a 5k filled with other serious runners. Then you realize where you stand.

As a younger/not so great developer - I used to think I was a great developer. I was the best developer in my family, the best developer of all my friends and when I finally got into programming classes at school, I was the best then. Even in college. And, honestly, even in a lot of the jobs I've had.

The reminder that there are other people out there who really are leaps and bounds ahead of me and the exposure to things I didn't know existed or were possible - gives me something to strive for.

The answers and resulting discussion, along with some tips I've developed on blogging added up to a fun talk where I eventually ran out of time. I hope to give this talk again in a more organized and formal setting in the future.


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 SherWeb

Low Bandwidth View and other Hidden (and Future) Features of MSDN

April 17, '09 Comments [37] Posted in ASP.NET | Microsoft | MSDN
Sponsored By

Ok, so I'm only 8 months late. ;) Last year MSDN quietly implemented a "low bandwidth" view.

Low Bandwidth MSDN

Basically, instead of visiting: 

you could add "(loband)" to the URL, like:

Instead of the standard MSDN page:

XmlNode Class (System.Xml) - Windows Internet Explorer

You'd get a nice streamlined version. This is great for not only low-bandwidth situations, but also phones, pdas, screenreaders, etc. More on that in a second.

XmlNode Class (System.Xml) - Windows Internet Explorer (2)

Jon Galloway noticed this last August and even made a nice bookmarklet to make it easier to get into this view. Fast forward until last week when I noticed that this existed. I started digging around, because not only was it cool, but my spider-sense was telling me there was more underneath the story.

I called Kim, the Development Manager for the project and I asked as many leading questions as I could, in order to find out what they were planning to do with this, how it was done, and if there were any hidden features. Sometimes folks kind of give MSDN a hard time for having fat HTML, lots of scripts, etc, and generally being slow. Turns out there's a whole ongoing project to make MSDN way faster and it's already seen some really significant improvements. I've got some internal slides she smuggled my way that I'm going to share with you here, so don't tell. I figure show first, ask question later, right? This is great stuff.

MSDN Performance

They use a number of tests at MSDN to see how fast the site is running, including Gomez and Keynote. Keynote and other tools not only do testing like YSlow and the like, but they do location testing to make sure the site is fast all over the world. That means testing it on a modem in China and DSL in Australia, etc. For example, you'll see Guangzhou, China appear in the slide deck a lot because it happened to be where MSDN loaded the slowest. The roll-up slides (for bosses) show Seattle, Paris and Beijing. In some places there was missing data.

Here's a slide from last Feb before the big performance push started. Notice the page sides is between 200-250k and the response time in China is 10 seconds. Good, I suppose, but not fast.


They'd test MSDN on first load, then second (cached) load. They called that PLT1 and PLT2 respectively. The first load of MSDN was like 1.3 megs. Insane. Adobe's site was 800k+, Java's was 800k+, but library sites like Ruby and Eclipses around 200-300k. A meg is not cool. They broke it down by JavaScript, HTML/CSS, Images, etc.


Over the next few months, they started moving CSS and scripts to separate DNS for HTTP Pipelining, reduced the number of redirects, were smarter about JS caching, lazy-loaded the Table of Contents. They started caching scripts at CDNs like Akamai and ChinaCache, reduced or removed ViewState.

Then the idea of flipping the whole thing on its ear happened. Rather than removing this and that, why not remove EVERYTHING, and only add back what was needed. Hence, the loband version was created.

Here's some performance tests between the loband MSDN on an unnamed technologies very-fast library site (you'll have to click the image to see the numbers):


The loband MSDN site can get sub-second times in the states and very close to one-second times outside the states, including Guangzhou, our previously slowest location.

Early versions of loband were 25k, but some changes brought the average down to just over 15k. Caching changes and other optimizations brought the performance by region down to under 2 seconds basically world-wide.


Here's an interesting graph showing the size of JavaScript, HTML and images on MSDN and a bunch of other sites, including In this chart, regular full MSDN in Feb of 2008 is the FAR left bar, and MSDN in July is the second from the left. The loband size is the second from the right.



You can click "persist low bandwidth view" if you want to make it your default. Also, they are paying close attention to the Feedback forum, so click that if you have more ideas. The next version of the loband site will be coming out in the next month and looks like this (sneak-preview):

XmlNode Class (System.Xml) - Windows Internet Explorer

They've removed the black bars, some markup changes, and the layout stretches horizontally better.

Additional MSDN "Switches"

I figured there can't just be the (loband) "switch" and I mentioned I thought that having to hack the URL was kind of wonky. Turns out that the whole MSDN system isn't a bunch of files on disk, but files in a database with an ASP.NET Virtual Path Provider. Tim Ewald wrote about how they did this WAY back in February of 2005. This was, at the time, kind of a poor-man's ASP.NET Routing:

The normalized path points to a file that does not exist on disk. Rather, the page data is stored in the content cache. The system uses a VirtualPathProvider (VPP) to bridge the gap between the two. In essence, a VPP intercepts all of the ASP.NET plumbing's requests for file streams and gives you a chance to load them from wherever you like. Every ASP.NET app uses a default VPP that simply maps to the file system. An MTPS-based site registers a custom VirtualPathProvider, which sits in front of the default VPP, forming a chain. The custom VPP uses the DocumentInfo and ContentSet objects that the HTTP module's OnPreResolveRequestCache event handler stored in HTTP context to load a topic from the content cache and return it as an .aspx file stream.

All of this is abstracted away, and what I'm calling a "switch" in the URL is what MSDN calls a "device" internally. The URL is just one way to indicate to their routing system that you are a certain device. The other way is via a User-Agent string, as you'd expect.

The content in MSDN is stored as XHTML, but then other controls are injected around it, similar to master pages. The whole page doesn't yet validate. If you think that's important, put it in the comments. If we get hundreds of comments here I'll pass them on to the team as "evidence," heh, heh.

There are in fact many "devices" for various reasons in MSDN. Most are turned on my User-Agent differences or for things like the Printer-Friendly view. However, you can force the device by inserting the device name in to the URL like:

There are also things called iRoots. For example, the word "Library" in the URL above is an iRoot. I could swap in the word "Magazine" and get a site that's skinned for MSDN Magazine.

Here's the devices I've figured out so far:

Low-Bandwidth - (loband)

This is the one we've been talking about. It's a minimal view, focused on one thing, speed.

PDA - (pda)

The best view for phones or PDAs. Turns off the left side navigation and makes the page 100% width and flexible.

Robots - (robot)

Optimized for search engines. Lots of meta data, no stylesheets, bare-bones. The Table of Contents is at the bottom of the page.

Printer-friendly - (printer)

Optimized for printing and includes a call to window.print().

Now, here's where it gets interesting...

MSDN Inside the (IDE)

When MSDN library content is viewed inside the Visual Studio IDE, a few things are added. First, the ability to Add Content via the MSDN Wiki is promoted to the top, as well as a "send" and "give feedback" feature. This is the view you get when you're inside the "Document Explorer" - the Visual Studio MSDN help browser.

MSDN for Visual Studio 2010

This is still up in the air, but you can see some ideas with the (dev10ide) switch:

XmlNode Class (System.Xml) - Windows Internet Explorer (3)

Here's a zoom in to a nice detail. Currently on MSDN online there's a filter dropdown to choose what language you want to see code samples in.


This live prototype has the languages for code samples appearing as tabs (as see above) including the option to "View Plain" or "View Colorized." There's also links to Copy to Clipboard or Print just the sample directly.

Future MSDN Plans

From what I hear from Kim, there's plans in process now for the loband site to become the default site this fall. They'll call it something like lobandlight and it'll have some small additions like a search box, selectable codeblocks, but the focus will be on being fast and clean. If you have opinions either way, leave them in the comments here or in the loband forums and they WILL be read by the MSDN team. Also, right now loband only works on the library, so while you can try these "devices" on other parts of MSDN, it's only currently designed to work with the MSDN Library itself. If you feel strongly that other parts of MSDN need loband lovin', let me know here and I'll pass your comments on directly to my boss.


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 SherWeb

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