Not even in my worst nightmare

I warn you, send your child to bed before reading this code snippet:

<span id="lblUser Birthday">User Birthday</span><br>
<input type="text" name="txtUser Birthday" ID="txtUser Birthday">

OK, the HTML4 DTD allows spaces inside the NAME attribute (it’s a CDATA) but it’s one of the worst practices I ever saw (even the control’s name autogenerated by ASP.NET web forms uses $ to separate names’ parts).

And spaces are not allowed inside the ID attribute.

Pragmatists would say that IE and Firefox are pretty tolerant and eat up everything, but this is pretty scary anyway.

I didn’t dare to ask “Who wrote this code?!

Technorati Tags: ,,
 

Configurable indentation for NHaml

NHaml, an alternative view engine for ASP.NET MVC written by Andrew Peters, uses indentation instead of opening and closing tags to identify code blocks.

If you never saw something written in NHaml here is taste of it. If you want to loop over a list and put it inside a unordered list with webform you would write:

<div class="list">
  <ul>
    <%foreach (var route in ViewData.Model) { %>
      <li><%= route.Name %></li>
    <% } %>
  </ul>
</div>

The same code in NHaml will be:

.list
  %ul
    - foreach (var route in ViewData.Model)
      %li
        = route.Name

The biggest problem of NHaml is that it’s behavior depends on the number of spaces you put at the beginning of the line: one level of indentation is made by 2 whitespaces.

Yesterday Andrew wrote a post on his site announcing the beta of NHaml version  2, and a few people, including me, complained that the default indentation of Visual Studio is 4 spaces, but someone even uses tabs. So, he made quick change in the code, and now NHaml features a configurable indentation (2, 3, 4, 5 spaces or even tabs). A very quick response to users’ requests, well done Andrew.

Technorati Tags: ,
 

How an extensive downtime influences traffic and search rank

At the beginning of October, the server that powered the Ugidotnet blog site (and all the other sites, including the article library and the forums) had a hardware failure (2 HDD in the RAID broke at the same time and some other bad luck) and went down. And it took a few weeks before the new server arrived and the admins of the server set it up again.

As result of this failure, all the blogs stayed offline for 12 days, from the 8th to the 20th of October. My Italian blog is not my primary blog, so I didn’t care too much of the downtime period: I thought that everything would have gone back as before once the server was up again. But I was wrong: today, which is almost one month after the restore of the server, I still receive only 1/3 of the visits I received before the crash (here the last month)

no-hits

What did happen? Probably Google, while refreshing its indexes, found the pages as not available and removed them from the its database. And when the site went back online it treated the it as new.

Here is the graph with the visitors coming to the site before and after the crash (last 12 months, visitors by week):

downtime

Maybe now it’s too early to notice an improvement, but I don’t see a growing slope, so I guess it will take long to go back to volume of traffic I had before.

This is a warning for everybody that is serious about blogging: if you are hosting your blog on a 3rd party blogging site, be it blogs.mysuburb.org, wordpress.com or blogs.msdn.com, you are putting yourself in the situation that you can loose traffic or, even worse, all your posts because someone unplug the service or the machine crashes. (I was lucky that one of the member of the ugidotnet team downloaded the backup of subtext database just 1 day before the crash, otherwise I’ll not be complaining about the decreased traffic, but also about the loss of all my posts).

And that’s the main reason why I started this blog on my own domain and on my own hosting space.

Before someone start misreading this post, I’m not pointing the finger to the ugidotnet team, which indeed did a great job restoring everything in such a short period of time, given the fact that they are all working on their spare time.

Technorati Tags: ,,,

PS: The drop in the stats is the usual traffic decrease caused by Italians going on holiday in July and August.

 

How to call controllers in external assemblies in an ASP.NET MVC application

If your ASP.NET MVC is growing large, it’s likely that you are partitioning your controllers in different namespaces, or maybe even in different assemblies, and it might happen that you have controllers with the same in different namespaces.

Phil Haack and Steve Sanderson wrote some great write-ups on how to partition an ASP.NET application down into Areas, a concept that exists in MonoRail but not in the core ASP.NET MVC framework. The two posts above allow grouping both the controllers and the views, so if you want a complete solution to the aforementioned problem make sure you read them.

What I want to point out here is that both the two approaches above are based on a hidden feature of the framework and the way the ControllerFactory looks for controller class. So it can be used in your own hand-made “area grouping” solution.

Let’s start directly with the solution: if you add to a route a datatoken named “namespaces” with a list of namespaces, the controller factory will look in these namespaces.

Route externalBlogRoute = new Route(
"blog/{controller}/{action}/{id}",
new MvcRouteHandler()
);

externalBlogRoute.DataTokens = new RouteValueDictionary(
new
{
namespaces = new[] { "ExternalAssembly.Controllers" }
});

routes.Add("BlogRoute", externalBlogRoute);

With the MapRoute helper method the things are easier since one of the many overloads allows you to specify directly an array of strings:

routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" },
new[] { "ExternalAssembly.Controllers" }
);

This is easier than having to remember the name of the datatoken key.

The default controller factory already takes into account the namespaces datatoken. In fact it follows this flow:

  1. Look in the namespaces provided inside the route
  2. if not found, then will look into all the namespaces

This is useful if you have many controllers with the same name in different namespaces: by specifying the namespace in the route definition, you are limiting where the framework will look for the controller.

As last point, if the namespace is in an external assembly, you have to add it as reference of the ASP.NET MVC web application project, otherwise it will not probe it.

kick it on DotNetKicks.com

Technorati Tags: ,,
 

SEO starting guide for ASP.NET

Today I just found two great sources of information on Search Engine Optimization.

Google’s search engine starter guide

The first has been released directly by Google: Search Engine Optimization Starter Guide

It covers the most common areas that might need a bit of optimization: urls, titles, metatags, image’s alt attributes, robots.txt file and other topics. A must read for everybody that is interested in the topic.

SEO for ASP.NET podcast

The second resource is the great (as always) podcast by Polymorphic Podcast about SEO for ASP.NET.

The guest, Michael Neel, talks about which are the main points of Search Engine Optimization, especially with ASP.NET.

And the main point is:

have the full url (without the query’s parameters) of the page, the page title and the H1 all with the same keywords.

All the rest is micro optimization that is irrelevant if the first golden rule is not applied. As also the Google’s document confirms, the description meta-tag is used to show the description of the page in the result’s list, but not used in the indexing of the page

Good to know… now I’d better change the structure of the HTML of my blog since the H1 is the blog name (codeclimber) and not the title of the post as are all the other two elements.

One good tool to help see the layout of a page is the “Document outline” command of the WebDeveloper toolbar plugin for Firefox. This is the outline of my blog as retrieved by the Document Outline tool.

document-outline

Then it covers also another interesting topic: ASP.NET Sitemaps. And finally, another sitemap, the one that Google can use to index exactly what you want him to index.

If you are interested in SEO, as with the Google’s doc, I really recommend you listen to this podcast: ASP.NET SEO.

 

Windows Live Writer doesn’t cope well with small screens

Probably the team that is developing Windows Live Writer never tested it with “small” resolutions: I’ve a 15” LCD display on my Dell D830 with a native (and thus maximum) resolution of 1280 x 800 and I cannot insert “object” inside my posts using the shortcuts in the left sidebar since they are at the bottom of the sidebar, and slip under the bottom status bar.

wlw-too-big

The biggest problem is the plugins are at the bottom of the list, so, even if I maximize the window, the second plugin will never show up. Ok, I can use the menu or the toolbar to insert a snippet of code, but using the sidebar requires just one click instead of two.

Not sure how they can solve this usability problem: maybe adding a scrollbar, or adding the possibility to collapse each section of the sidebar (Drafts, Posted and Insert).

Technorati Tags: ,
 

Red X on Build folder on Team Explorer

Today a colleague asked me to allow him to schedule a new build on the project. I thought “he is an admin of the project, he should already be able to do so”. But still he was not able to access the list of builds.

Looking at his Team Explorer he had a red X on the “Build” folder: this was even more strange because usually the folder is named “Builds” (with the s). On the left is my colleague’s team explorer, and on the left it’s mine.

Red_X_Build_folder  correct_build_folder

It seems like it’s a pretty uncommon problem, since I had a hard time finding someone else with the same problem and after a few searches I found this post on the MSDN forum: Red X on Build node.

My colleague didn’t upgrade from TFS2005 to TFS2008 as happened to the other people on the thread, but the proposed solution worked fine:

first of all you should to rename the cache folder for Team Foundation "C:\Documents and Settings\[accountname]\Local Settings\Application Data\Microsoft\Team Foundation\2.0" (in Vista or Windows 2008 the path is “C:\Users\[accountname]\AppData\Local\Microsoft\Team Foundation\2.0\Cache”)

Then execute this command line: Start > Run : “devenv /resetuserdata".

With this you reset your VS user data, you must to be care with this because you will lose all your personal options for VS, but this solve the problem for me.

I’m not sure what it might have caused the problem, maybe, as someone suggests in the thread, some corruption of the profile or a failed Power Tools installation, but this solved the problem without many side effects (unlike the other proposed solution, which was to delete your local user profile and recreate it from scratch).

Technorati Tags: ,
 

How to start the day in good mood in a rainy November morning

swimmingpic

  1. Stay up till 3am to work on an ASP.NET MVC book and write some samples on alternative view engines
  2. Wake up at 7am and tumble out of bed
  3. Grab the Vespa and ride 20 minutes under a pouring rain
  4. Got to the swimming pool, and swim for 1000 meters
  5. Walk to the subway station (and leave the Vespa to your wife), still under the rain
  6. Go to work while listening how pragmatism and getting things done killed the purism and the security concerns (ie How Stackoverflow was built)

And this is not sarcasm: the 30 minutes of swimming and listening to how StackOverflow was build, with not attention to physical security, no tests as would have delayed the release and with less-than-best-practice architecture really lightened my morning start, regardless of the only 4 hours of sleep. There should be more of this kind of podcasts.

Technorati Tags: ,
 

One year at Avanade

Exactly one year ago I started working at Avanade: wow, time passed fast, way faster then the 10 months I worked for Calcium (7 of which in Wellington). And now that I think, it’s the my second longest job.

Another funny coincidence is that the weekend before starting my job I was showing Milano to David Silverlight, and this weekend I showed Milano  (and other cool places around, including a flooded Lake Maggiore) to another of two guys I met in NZ through the “enlarged” .NET community, Nic Wise and his wife Leonie.

But back to the main topic: Avanade is great place to work, I feared it was more Accenture-like (which means, at least in Italy, 12hrs a day and at least one weekend per month), but it is not. And comparing to my previous experiences, where I had no training provided and no possibility of professional growth, here is the opposite: training, possibility to make a career, to attend to Microsoft conferences are invaluable. And for a technology enthusiast like me, the close connection to Microsoft and the deep technology focus of Avanade are a big plus of the job.

The only downside is that most of my time is now spent managing a team, so I don’t get to write a lot of code: but I guess it depends on the size and the scope of project you end up working for. On the other side, this is good since I love to share my knowledge, and help other people grow.

Another thing I think is good about this first year is that I started working with technologies I never really used before, like MSBuild, Reporting Services, Notification Services, and a little bit of Sharepoint.

All in all, a very positive first year. Looking forward to seeing how the second one will be.

Technorati Tags:
 

How to keep track of ideas with a mind map

Lately I’ve been a bit busy writing a book on ASP.NET MVC and with some Microsoft events, so unfortunately I didn’t have a lot of remaining spare time to write the interesting posts I used to write before. But my mind never stop running, so sometimes an idea for a good post popped up in my mind. At first I thought I would have been able to remember them all, but soon I discovered I was keeping forgetting them, so I looked for a solution to this problem. And I found out a post that suggested (sorry, don’t remember which one it was) to use a mind map to keep track of all the ideas. The mind map format also allows the ideas to flow, as from one idea many other might come out, like other posts on the same topic or more in-depth posts.

And among the few online mindmapping tools I found, I started to use MindMaster (the other options were bubbl.us and Mindomo) which has a free membership that includes 6 maps.

Down below is my current mind map with the ideas for posts I collected in the past few months:

mindmap

So, as soon as I finish writing the book, which will hopefully be done by mid-late November, I’ll go back in blog writing mode, so, stay tuned as there are interesting posts on the way.

Technorati Tags: ,,