Creating Explicit Route To Website Homepage In ASP.NET MVC

Typically, you have this standard piece of routing configuration:

    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}

Which does the job of matching “/” to HcomeController‘s Index action.

The reason it works is simple, the id parameter is obviously  optional, the action parameter if not present will be set to Index, so, this routing will match “/home/index/”, and similarly will match “/home/”. But the controller also will be set to HcomeControlimageler if it’s not present (the Controller suffix is a convention in class name), so, this matches “/home/” and “/”.

Using Explicit Route

Until here, there is no point of this blog post. So, lets say for whatever reason you are using other routing rules, because your desired routes don’t follow this very convention or because you don’t want to couple public URL structure to internal class names or have another reason to make your routes explicit, how do you set a route for the homepage or website root “~/” URL in this case?

One possible case is to have this exact default route still there, but make sure it’s at the very end of your route registrations, after all other have been registered, so, it has the least priority in matching. The drawback is that it’s still more generic than its purpose, technically allows using it for other actions than the one handling the homepage, and every request to homepage will go through all routes tried first (which is usually not a very slow thing to be honest).

So, a nicer way is to be able to have an explicit homepage route. Maybe even one that can be put on the top of route registrations to make the request to our homepage the fastest ever (although again, it’s not a big deal or difference, but nice to have). Turns out the way is VERY easy, just set the URL to an empty string “”.

    name: "Homepage",
    url: "",
    defaults: new {controller = "Home", action = "Index"}

Yeah, that’s it (the “name” doesn’t matter BTW, and you can obviously use whatever controller/action too). Even if you are using the default routes, you can combine it with them, and put it before them too. Empty string will NOT match any URL that is not empty (you can argue all other requests are matched against this, but comparing a string against an empty one must be VERY quick, right?)

Note that this all is application specific, so, the root here is website root “~/” not server root, so, this should still work if your website is hosted under some virtual directory too.

Not that it matters a lot, but thought some of you would be interested :).

Have fun.


Lowercase URLs in ASP.NET MVC, The Easy .NET 4.5 Way And Other NuGet Options

If you wonder why you should care about creating lower case URLs at all, or what this actually even means, skip to the appendix at the end.

Earlier, the easiest way I have found to create lower case URLs (URL paths, not query strings) was to use the NuGet package LowercaseRoutesMVC, and modify the routing code, to use the library’s own MapRouteLowercase() extension method, instead of the built in MapRoute()extension.

For example, instead of:

    new { controller = "Home", action = "Index", id = UrlParameter.Optional }

You write:

    new { controller = "Home", action = "Index", id = UrlParameter.Optional }

The .NET 4.5 Way

.NET 4.5 introduced a new property to the RouteCollection class instances (the “routes” parameter in the code above is an instance of it).

The new property is LowercaseUrls.. Remember that routing is not shipped as part of ASP.NET MVC code, but part of the NET framework itself. So, this property is available to you as long as your project uses .NET 4.5+, whether it’s ASP.NET MVC 3 or ASP.NET MVC 4.

Usage is very simple, just set the property before you map your routes (or after the mappings were added, works as well):

routes.LowercaseUrls = true;

The Result

Either you are using the third party NuGet package, or the standard .NET 4.5 property, after making the changes to the routes, this is what you achieve:

Lowercase URL Generation

All helpers used in in ASP.NET MVC to generated action URLs registered in the URL route mappings will generate lowercase paths. For example, Razor code:

@Html.ActionLink("Log On", "LogOn", "Account")

Will generate the following HTML:

<a href="/account/logon">Log On</a>

Lowercase URL Resolution

Of course the generation wouldn’t be complete without revolving the lowercased URL path back to the correct controller action. In the above example, the “/account/logon” URL will be resolved (assuming the default routing used in the first example in the post) to the LogOn action of the AccountController controller.

However, this is not accurate in fact, because typically we all get this already. Routes in ASP.NET MVC are not case-sensitive by default, so, both /account/logon is the same as /Account/LogOn to ASP.NET MVC.

If you want to force redirection to the lower case paths, for SEO or else, you can (very easily) do that with IIS 7+ and Url Rewrite module. I learned about it by trying, but here is an example of how to use it, and also an official video.

Using The Built-In Way Vs. The 3rd Party Options

The obvious difference is that the NuGet package require you to change every route call explicitly while the built-in way takes over all routes. If you are decided that any non-lowercase route is a developer mistake, then the built-in option may be a better way to minimize developer human error, if you need control or need to exclude some routes from this, then maybe the NuGet package is more suitable.

Note that this specific package hasn’t been updated since last Novemeber, but there are other similar packages on NuGet anyway, and it shouldn’t be too hard to implement one yourself.

If you care about routes and URLs as much, you may also considering writing tests for them.


There is another NuGet package specific to ASP.NET MVC 4, which includes experimental ASP.NET Web API as well. The package is: LowercaseRoutesMVC4. If you are interested in the project source code and more,, check out the LowercaseRoutesMVC project page. Again, note that this has been last updated on November 2011.

You’d expect the built-in property to affect Web API as well as it’s part of .NET 4.5 not 4.0, and as mentioned before it surely works with ASP.NET MVC 4 as well as ASP.NET 3. I’d personally use it by default in any future project..

Appendix: Why Should You Care?

Lower case URLs have already become the de-facto standard for so long. Historically, when all path URL parts were one-to-one mapped to physical file paths (excluding hashes, and query strings), this required URLs to be case sensitive because Unix file paths are case sensitive (and hence, Linux and so, unlike Windows). Search engines also had to respect this as well, as there is no guarantee that /directory/file.html is the same as /directory/Filename.html, or /Directory/filename.html or /DIRECTORY/filename.HTML, etc..

So, in brief, it’s better for SEO, and it’s becoming the industry standard anyway (for those who care), as showed earlier, even Microsoft has made enforcing lowercase URLs although not the default but a really easy thing to implement (regardless of the technology you use, the URL Rewrite module is enforcing lowercase URLs on this blog for example, which uses PHP (WordPress).

By generating lowercase URLs combined with the Url Rewrite Module, you save the users extra redirection steps, unless they decide to write the URL in a non-lowercase manner themselves.


Search Engine Optimization (SEO) Secrets On My Blog – Advertising Also

Just a hour ago, I got an interesting question via the contacts page in this blog, about search engine optimization, and I wanted to share the answer with you…

The question is:

I’m a software engineer and SE Optimizer. I’m currently assigned a project that needs general information of the mini sites and blogs regarding their SEO strategy and daily revenue. I read your blog a lot in my .net related problems and thought of finding the details about your blog.
I found out that there are daily ~900 page views of your blog and your page rank is 3.

Mohamed what I wanna know is that whether you have employed any SEO strategy on your blog or this is just the good will traffic that comes to view your blog.

Also what is the daily ads revenue of your blog and what kinda ads you have deployed on your blog.

Although my Google Analytics statistics tell me slightly better results than mentioned in this message,, this is an interesting question I’d love an answer indeed. Scott Hanselman taught us though it’s better to reply to those in public and share the benefit with everyone, let’s see:…


In fact, I do not have special SEO strategy. but here are some highlights:



I used to have a blog at GeeksWithBlogs.NET (in 2005), a high rank .NET blog host, then moved to (2008), which is sub domain of the official ASP.NET site, I made sure the new blog URL shows in the title and description of the old blog., and re-posted the items that seemed to have high referrals from search engines.

When I moved to my own domain, GuruStop.NET (Feb. 2010), I imported all previous posts to it and wanted each post in the domain to redirect to the corresponding post in GuruStop.NET.


I created an ASP.NET redirector page on my new hosting that uses permanent redirection to a post based on post title part of the URL (slug) and date parts also. The redirector used to depend on referrer URL and if not present then on query strings.

To point to the redirector ASP.NET page from the old blogs,  I used a combination of HTML meta refresh redirections (which didn’t seem to work well with referrers) and JavaScript redirection as well.Yes, it’s true that search engines will not realize the JS redirection, but people getting search engine results in old blogs will be visiting the new posts, and this is sure one-way-or-another will improve the page rank.


Cross Posting

In my previous blog move, I used cross-posting to keep links coming to my blog. One drawback of this is so many duplicate posts coming up in search engines. For a new domain like GuruStop.NET, I could not do that as it could also harm the page rank of the domain.


Avoiding cross posting is one of many Scott Hanselman tips for bloggers. Those are VERY valuable when I started this blog.


Post Link Sharing and Social Bookmarking

On the other hand, mentioning older blog posts in newer ones, and even in my public sessions/presentations and/or private emails (when relevant to the context of the email not as spamming) to mailing lists and/or friends, as well as announcing new posts on my twitter and facebook accounts, has shown a pretty interesting effect in getting more people (and high rank people) to notice some of my posts. One example off my head for getting high rank readers is my post about choosing an ORM.


Sharing links on social bookmarking sites, either general like Digg or .NET specific like SotNetKicks or DotNetShoutOut seemed to help, but not sure to what extent. I’ don’t always do it anyway.


One note about sharing buttons (like “Digg this post”, “Tweet It”, ….) either in the post itself or in RSS feeds, those did not seem to get used at all! Some people liked a few posts enough to submit them to social sites, but almost none used the sharing buttons to do so.

One other thing that didn’t seem to be very useful is announcing new posts in general developers lists, at least talking about Egyptian ones.


Topics, Keywords, Titles, URLs (Permalinks), …

I tend to believe that correct titles, as well as choosing rare topics when possible to write about (one reason behind low rate of posting), are the main reasons behind the fact that most of my audience usually come from search engines!


URLs / Permalinks

Of course, like most blogs, I use pretty URLs / Friendly URLs / Pretty Permalinks for all my blog posts, category(ies), tags, etc.. I cared about getting extension-less URLs also, although I don’t believe this was a difference. I use the standard /blog/year/month/day/slug/ style for all posts.

Pretty standard, ha? I considered omitting parts of the date like day or omitting it all, but thought, when I go to any blog, I usually look at the URL of any post I read in a new blog to tell it’s date. It’s much easier for me than looking at the page however clear the post date shown in it is. I didn’t want my readers to miss this “feature”.


Titles / Keywords / Tags

Typically, I depend on making good post titles (My blog engine automatically converts the title to URL part (slug) as well). The title is always full of the relevant keywords to the topic.

When the same topic can in expressed in 2 ways or more, I make sure to mention all of them. I use the most common one in title, then the less common one in the first paragraph of the post, and if there are more, make sure to mention them either in brackets or  in following paragraphs.


I also make sure to include as many related keywords (tags) in all my posts. Yes, the tag menu on the right of this blog is maybe not the friendlier (yet still usable), but I it’s hardly used to navigate the website anyway. Not sure if this is affecting in any way though. I tried Technorati tags widgets before as well (from those built-in Windows Live Writer), but those were completely the same either included or not.



Whenever possible, I try to avoid writing except rare topics, where I really have something different than written before. This makes  the one who has similar need to the one I wrote about find my post easier. I do not try to go in the race of the repeats and duplicates whenever possible, at least in post titles.

This is sure easier when there are many new technologies coming, or when working in rare field with flexible time for writing. however, sometimes I just remain lazy unaware of the things I have in my freelance or day work code that can be worth sharing here. It’s a double-edge weapon indeed!


My Name IS A Trademark – The Blog Name Also Is

One important keyword is my own name! I have chosen to give the blog its own trademark “GuruStop” and stick to that, but it is still important that if someone looks “GuruStop” or “Mohamed Meligy” up in Google s/he’d find this blog showing up.

For GuruStop I dedicate the blog domain as well as the blog title. For my name, I make sure to put it first thing in the sub title, and put it different areas here and there. Currently I need to manage my SEO plug-ins to have better control over the meta description for just that.


The Automatic Stuff, SEO-Related Plugins

This blog uses WordPress as a blog engine. I have made that decision after reviewing so many .NET blog engines and being not-satisfied-enough about them all. One good benefit of the long age and popularity of WordPress is the huge amount of plug-ins available for it. I take advantage of that.

Some of the plug-ins I use include: “All in One SEO Pack”, “All In One SEO Pack Windows Live Writer Bridge”, “Core Tweaks WordPress Setup”,  “MetaWeblog API Client”, “pageMash”, “Post Layout”, “search engine related posts”, “Top Level Categories”, “Yet Another Related Posts Plugin”, “SEO Automatic > Core Tweaks”


Of course I keep an eye on my blog usage from time to time using Google analytics, etc…


Ads / Advertisements

I solely use as an advertisement platform on this blog. Reason is: They’re focused on .NET community, so, they probably have higher possibility of providing value to my readers just like my own posts (They run the ads on big sites like CodePlex and other big names. I had to show them some Google Analytics statistics to get accepted!).. If the ads serve the marketer only not the reader, they’re no more than a piss-off to my readers.

Currently I only get $8 to $13 per month. This is hardly the hosting cost of this weblog.  I haven’t yet pulled that from PayPal since the total is still below $50. Watching my ads statistics, it was very natural to realize that the more I write new posts in a month, the more ad revenue I get.


Before I went for that, I used Google Ads, images only. A friend told me text ads are way better but I thought the audience of the blog (mostly developers) must have become ad-blind against the well-known pattern of Google text ads. I couldn’t evaluate the whole experience well by then anyway, so, I moved away.


One thing to note about ads is how they’re placed in this blog. You’ll notice there is only one ad per page, and the ad location of the homepage is different from post details page. This is on purpose (and got me some JS workarounds to get working right).


Room for Improvement…

I have to admit that I’m missing much in this blog SEO area though (and ads). I could have done much more:

  • Modify meta keywords manually for each post
  • Use a custom URL slug with only SEO keywords not entire post title (which may have a lot of “a”, “in”, “for”, “the”, “I”, …. )
  • Add even more ads!
  • Write more posts!! (I know I know, lazy me)
  • Do some effort on sharing my posts in .NET social bookmarking sites
  • I used the “Blog” category for all posts just in case I use the domain later for more stuff. Maybe I better give up this never-coming planning and / or use sub categories in addition to tags (but less fewer).
  • Probably I should market my other methods of contact as well. Should put my twitter ID in clearer area of the blog theme for example, etc…
  • Another Reminder: More posts are needed, “Content is the king”.
  • … and sure there is more!


    Your Experienced Suggestions…?

    If you are reading this and you do have a blog or some experience in SEO, it’ll be great to put it in the comments for the readers, and/or post it to your blog and link it in the comment.

    Such calls for actions have been pretty successful in previous posts, hope this one is different Winking smile