# Wednesday, 18 November 2009

I found this question on the ASP.NET forums. The member asking this question already knew that the collections were Cookies, Form, Servervariables and Querystring but wanted to know the exact order. Well I got curious but instead of making a dedicated test project I opened up Reflector. Looking up the HttpRequest class’ indexer gave me this code:

public string this[string key]
{
    get
    {
        string str = this.QueryString[key];
        if (str != null)
        {
            return str;
        }
        str = this.Form[key];
        if (str != null)
        {
            return str;
        }
        HttpCookie cookie = this.Cookies[key];
        if (cookie != null)
        {
            return cookie.Value;
        }
        str = this.ServerVariables[key];
        if (str != null)
        {
            return str;
        }
        return null;
    }
}

 

It’s on the other hand always better to directly call the most specific collection directly. This avoids getting strange things in your code like expecting a key in the Form collection and getting the same key from the QueryString collection which could have a different, or none at all, value than what you expect. Fun debugging sessions follow after that…

Grz, Kris.

Wednesday, 18 November 2009 05:02:00 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Sunday, 07 June 2009

The first time I encountered .NET Reflector was at Techdays Belgium in 2003 during a session. I got interested in this valuable tool and used it ever since for disassembling .NET assemblies to code and take a look at the inner workings. If you haven’t downloaded it already then you can grab it here.

A little known fact is that one can also extract embedded resources with this marvelous tool. When you simply open .NET reflector like in figure 1 you can navigate in the treeview to System.Web > Resources.

reflector01 
Figure 1: .NET Reflector assemblies overview

Then scroll down until you find the resource with the name WebUIValidation.js. Right click on it and select Save As… like in figure 2:

reflector02
Figure 2: Save the resource.

After this action a Filesavedialog window will open so you can save the resource to disk.

 

Also be sure to check out this demo movie from Redgate itself which shows some nice standard features if you’re not used to working with the product.

Grz, Kris.

Sunday, 07 June 2009 22:55:00 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  |