Archive for August, 2007


Fiddler2 and the ASP.NET Development server (Cassini)

If you’re debugging ASP.NET apps, it can sometimes be an advantage to be able to see the actual requests, and analyze file sizes, run-time rendered code and being able to ‘fiddle’ with the code on run-time. Well. Fiddler2 provides extremely useful features for doing so, but for people using the ASP.NET development server (Cassini) you have to do a few workarounds…

I’m running IE7 on Windows Vista (a great OS). IE7 automatically bypasses proxies for localhost, which is our main problem. When using the ASP.NET development server (Cassini), the URL looks like this one: http://localhost:49950/app/Default.aspx. When you open Fiddler2, you see that it hasn’t monitored the traffic to the localhost address. This can be fixed by applying a period (.) after localhost. So change the URL to this:  http://localhost.:49950/app/Default.aspx

In my case, that wasn’t enough. I got an error from Fiddler2 in my browser. If I disabled Fiddler2, it worked just fine. Then I added a rule to Fiddler2. To do this, in Fiddler2 go to Rules > Customize rules. (or hit CTRL + R). Find the OnBeforeRequest event-handler, and add the following code:

if (oSession.host.substr(0, 10)==”localhost.”)
{
         oSession.host=oSession.host.replace(“localhost.”, “127.0.0.1″);
}

Now – when you want to use Fiddler, just add a dot right after localhost in the URL, and Fiddler will start working!

That worked for me – hope it works for you too, if you’re having problems.

Set the DataTable.Locale property – or get weird sorting

If you have a monster of an ASP.NET app, and your user come from different places in the world, they are most likely to have different locales as well. I’m danish, and we have three special characters in our alphabet – æ, ø, å. If I have a DataTable with – let’s say firstname and lastname columns. I create my DataTable like this:

      DataTable dt = new DataTable();
      dt.Columns.Add(new DataColumn("Firstname", typeof(string)));
      dt.Columns.Add(new DataColumn("Lastname", typeof(string)));
      dt.Rows.Add(new object[] { "Øjvind", "Jensen" });
      dt.Rows.Add(new object[] { "John", "Nielsen" });
      dt.Rows.Add(new object[] { "Åse", "Østergaard" });

This is how I DataBind my GridView:

      if (!Page.IsPostBack)
      {
        GridView1.DataSource = dt.DefaultView;
        GridView1.DataBind();
      }

With my regional settings on my machine (which in this case is also the webserver) we get the correct sorting:

image
The GridView sorted by Firstname ascending.

But if I go ahead and change the settings of my machine, to English (United States), my GridView will look like this, when I sort it by Firstname ascending:

image

This is because the server compares the strings wrong. So if you’re dealing with users from around the globe – you have to set the Locale property of the DataTable – this is done like this:

dt.Locale = System.Globalization.CultureInfo.CurrentCulture;

Now this I cannot test on a single machine. This is because the above code takes the CultureInfo of your machine, and since I just changed my regional settings, I get the GridView sorted wrong. So I fired up my old laptop, this time with FireFox the GridView looks like this:

image

From a user perspective, a GridView sorted incorrectly is very bad. So to add this single line of code is really not a big deal.

Technorati Tags: , , ,
Powered by WordPress | Theme: Motion by 85ideas.