8 Comments

ASP.NET has an outgoing connection limit which is set to 2 connections by default. It means that the ASP.NET process does not create more than 2 concurrent connections simultaneously, but instead queues them up.

Consider the scenario where you call 4 web services asynchronously from the same method. What happens is that the first two starts to execute, while the next two waits for the first two to finish. The same thing happens for HttpRequests.

That is a waste of time in most cases, so you can raise the connection limit to allow more simultaneous reqests in the web.config.

<system.net>
  <connectionManagement>
     <add address="*" maxconnection="8"/>
  </connectionManagement>
</system.net>

Every asynchronous request is started in its own thread, so you have to be careful not to raise the limit too far. The more CPU’s or cores the web server have, the higher can you set the connection limit.

You can read more about asynchronous requests and the connection limit on MSDN.

0 Comments

I’ve been fiddling with accessibility standards and validation today. It’s something I’ve been doing for several years now on many different types of web applications. So today it was time for my blog to go through validation and it almost did.

Section 508

First, I started out with the Section 508 standard, which as far as I know only applies in the US, but nevertheless it is an accessibility standard and I know it is much more forgiving than WAI. It passed the Section 508 without I had to change anything, so that was easy.

WAI A

Then it was time for the WAI validation. It is not as forgiving as Section 508 and in Europe all public websites have to be valid WAI double A, which is the medium accessibility grade. I ran the Bobby validator and it didn’t even validate for single A. However, that was an easy fix.

WAI AA

Then I moved on to WAI double A and ran into serious trouble. It validated except for this rule: Do not use the same link phrase more than once when the links point to different URLs. This is impossible to fix, because at the bottom of each post there is a Permalink, Post RSS and Comments link which are almost the same for each post even though they point to different locations. Also, some tags are the same as a category, but again, they point to different locations.

Sticking with WAI A

So, I was left with a choice. I could change the text of the links or accept that my blog does not validate WAI double A. The problem is, that you cannot have triple A valid markup if you don't pass the double A validation. I came to the conclusion that renaming the links would be ugly and do more harm than not validating, so it all ended right there. I have to settle for a single A and a Section 508 valid website. It could be worse.

Other validators

Then I saw that W3C has released a beta version of their new markup validator, so I decided to give it a go. As I hoped, my blog validated perfectly XHTML 1.0 Transitional. I was then pointed to the Semantic Data Extractor which exposes the semantics of a webpage to give you a clear picture of how the text is structured. Here is the semantics of my blog. It looks quite nice I guess.

I like validating markup and always have. It has some meditative quality about it.

0 Comments

Some people have asked me how BlogEngine.NET displays a dropdown list of countries when no source XML file is present. The simple answer is that you don’t need any external list to bind to from C#, you can instead use the CultureInfo class.

Consider that you have the following dropdown list declared in an ASP.NET page:

<asp:DropDownList runat="server" ID="ddlCountry" />

Then from code-behind, call this method which binds the countries alphabetically to the dropdown:

public void BindCountries()
{
  System.Collections.Specialized.StringDictionary dic = new System.Collections.Specialized.StringDictionary();
  System.Collections.Generic.List<string> col = new System.Collections.Generic.List<string>();

  foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
  {
    RegionInfo ri = new RegionInfo(ci.LCID);
    if (!dic.ContainsKey(ri.EnglishName))
      dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());

    if (!col.Contains(ri.EnglishName))
      col.Add(ri.EnglishName);
  }

  col.Sort();

  ddlCountry.Items.Add(new ListItem("[Not specified]", ""));
  foreach (string key in col)
  {
    ddlCountry.Items.Add(new ListItem(key, dic[key]));
  }

  if (ddlCountry.SelectedIndex == 0 && Request.UserLanguages != null && Request.UserLanguages[0].Length == 5)
  {
    ddlCountry.SelectedValue = Request.UserLanguages[0].Substring(3);
  }

The method first adds all the countries from the CultureInfo class to a dictionary and then sorts it alphabetically. Last, it tries to retrieve the country of the browser so it can auto-select the visitors country. There might be a prettier way to sort a dictionary, but this one works.

0 Comments

Normally, I don’t dedicate an entire post to a remote link, but this is no normal case!

Douglas Crockford, whom I’ve never heard of before, did a speak recently at the 2007 FrontEnd Engineering Summit about code quality and the kind folk at Yahoo recorded it for everyone to see.

It’s a long video but it is worth watching it from start to finish. He has a huge insight into the history of software development and makes some really good analogies that help to understand what he talks about.

If you only watch one video this year, then this video should be the one.

Check out Douglas Crockford on code quality.

8 Comments

There seem to be some confusion about the Google Sitemap support of BlogEngine.NET, so I thought I would elaborate on it. First of all, BlogEngine.NET has a build-in sitemap handler so you don’t need to write it yourself.

BlogEngine.NET comes with many build-in handlers such as:

  • microsumary.axd
  • sitemap.axd
  • syndication.axd
  • commentfeed.axd
  • opensearch.axd
  • rsd.axd

…and more not so interesting ones.

All the handlers are accessible by typing http://www.yourblog.com/handler.axd where handler can be any one of them. So, in order to see the generated Google Sitemap just type in http://www.yourblog.com/sitemap.axd in your browser. Here is mine.

Auto discovery

You can tell Google manually about the location of your sitemap file or you can put the URL in the robots.txt file. I recommend putting it in the robots.txt because then Yahoo, MSN, Ask and Google can find it. Yahoo, MSN and Ask also supports the Google Sitemap format.

Just add this line to your robots.txt file:

sitemap: http://www.yourblog.com/sitemap.axd

This line can be the only line in the robots.txt if you don’t want to provide more information to the robots and spiders.

I hope this clears things up.