HttpValueCollection.ToString() generates your nice query strings

by Jon Sagara May 24, 2008 at 6:43 PM

In an ASP.NET page, if you call Request.QueryString.ToString(), you'll get a nicely formatted query string back, like this:

 my=query&string=value&foo=bar

"That's nice," I thought.  "I wonder how they implemented it.  I'll fire up Reflector and take a look."

However, when you look at the declaration of QueryString in HttpRequest, you'll see that it is of type NameValueCollection, a class that has no ToString() override; at first glance, it looks like you'd simply be calling System.Object.ToString().

Obviously, this is not what is happening, so to find out how the query string is being generated, I had to dig just a little bit deeper.  Fortunately, VS2008 lets you step into the framework.

When you step in you'll see that HttpRequest.QueryString is indeed defined to be of type NameValueCollection, but when it actually gets instantiated, it is initialized to be of type HttpValueCollection, an internal class that derives from NameValueCollection. 

HttpValueCollection has a ToString() override that does the dirty work of constructing the nice query string that you see at the top of this post.

I'm so glad that Microsoft decided to allow us to step into the framework source code.  Otherwise, I probably would have spent a good hour trying to track down the magical NameValueCollection.ToString() call.

Tags:

Blog

Why I buy eBooks whenever possible

by Jon Sagara May 21, 2008 at 8:27 AM

I've recently started purchasing "eBooks" whenever possible because they are just so dang convenient.  I can easily share them between my different machines, so I no longer have to lug a bunch of heavy books back and forth between home and work.

That's an obvious benefit.

A really cool benfit, though?

If you buy from a forward-thinking publisher with great customer service, they'll do things like provide you an updated copy of the book that includes fixes and errata.  Here's an email I recently received from Manning Publications:

Dear Manning Customer,

You previously purchased the Ebook version of ASP.NET AJAX in Action from the Manning online store. Since that time the author has provided a few corrections and other errata that we have incorporated in an updated version. As a courtesy we are making the updated Ebook available to all who purchased the original. Below please find the link to download this updated version.

When's the last time a book publisher mailed you an updated version of your hard copy, just to distribute errata?

That is just so awesome, and totally unexpected.

Manning seems to be keeping up with the latest technologies, and the 3 books I have purchased from them have been worth their weight in gold.  I am a repeat customer, and if you're looking for tech books, I urge you to give them a shot.

Tags:

Blog