ASP.NET MVC: Defining short URL-s for root level pages
Short URL-s are more and more important part of page usability as mobile internet is growing. Long URL-s are not convenient to type due to small keyboards and screens of mobile devices. Also short URL-s are easier to remember and using well chosen short URL-s your pages may also get better rankings in search engines indexes. In this posting I will show you how to create short URL-s for ASP.NET MVC pages.
Default routes
Routes used by default are part of ASP.NET MVC applications right from start. After creating new ASP.NET MVC application you can find the following RegisterRoutes() method from Global.asax file.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
} // Parameter defaults
);
}
IgnoreRoute() call here sais to ASP.NET MVC that *.axd files need no processing. Call of MapRoute() method creates new route and sets the following default values:
- controller – if controller name cannot be found from URL then take HomeController,
- action – if action cannot be found from URL then take Index() as default action,
- id – it is optional and may be omitted.
We can define other routes too if we need.
Shortening URL of About page
As all ASP.NET MVC applications get by default also page called default we can use it to analyze its default URL and create shorter URL after that. By default, About page has the following URL:
http://yourhost/Home/About
As Home controller is all about “default” pages as activities that happen on root level of site we don’t have any good reason to keep word Home in URL. In SEO terms it increases the distance of page title and in some cases shorter URL-s perform better in search engines.
To get short URL like this:
http://yourhost/about
add the following route definition to previously shown method, right before last route definition.
routes.MapRoute(
"ShortAbout",
"about",
new { controller = "Home", action="about" }
);
When you run your application you can see that ASP.NET MVC generates short URL for About page automatically.
This solution works well if you have only some pages under root level of site. This is default case for many pages. Of course, it is possible to write more code and have more advanced routing that handles all short URL cases but right now I think this way you move quicker.
Conclusion
ASP.NET offers powerful routing mechanism and MVC framework makes good use of it. Sometimes we may need better URL-s for root level pages than the ones that are generated by MVC framework by default. There may be pages like About, Terms, Join, Log in etc. If we don’t have many pages on root level we can easily define new routes for these pages that offer shorter URL-s that are easier to remember and easier to type on mobile devices. Also search engines may give better rankings to our pages if we don’t use longer URL-s. We saw that it was easy to add new routes to routes collection for pages that need shorter URL. Our method works as far as there are not much pages on root level of site.
In your case it would be easier to write a single route that would cover the same scenario as multiple ones:
routes.MapRoute(“ActionOnly”, “{action}/{id}”, new { controller = “Home”, action = “Index”, id = UrlParameter.Optional });
And when you want to cover other controllers as well, you may add some route constraints that limit action names to particular ones as:
routes.MapRoute(“ActionOnly”, “{action}/{id}”, new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }, new { action = “about|index|help|settings|account|etc…” });
@Robert,
I like your solution…I assume you could make this a string that comes from a database or a config file (the delimited actions)?
Thanks
Thanks Robert! I was looking for a solution for a SEO better URL in MVC3 and Roberts comment gave the final touch with the use of constraint in the route.
Hello there! Quick question that’s entirely off topic.
Do you know how to make your site mobile friendly? My
blog looks weird when browsing from my iphone. I’m trying to find
a theme or plugin that might be able to resolve this
problem. If you have any recommendations, please share. Thanks!
Please let me know if you’re looking for a article author for your blog.
You have some really good articles and I feel I would be a good
asset. If you ever want to take some of the load off, I’d really like to write some content for your blog in exchange for a
link back to mine. Please send me an e-mail if interested.
Thank you!
antalya psikolog
I’m excited to uncover this page. I want to to thank you for
ones time for this particularly fantastic read!! I definitely appreciated every little bit
of it and i also have you saved to fav to check out new things in your blog.
Hey there! This is my first comment here so I just wanted to
give a quick shout out and say I truly enjoy reading your
posts. Can you recommend any other blogs/websites/forums that cover the same subjects?
Thank you so much!
Greetings readers! This article was so valuable. I suggest you
get sidebar backlinks from virgool.io. If you want to rank better, DM me on Telegram @myd_80 or visit my SEO group @seoprem.
We have guest posts for sale. Also, the best telegram seo group and the
magic of internal seo is for mehran yousefi at https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx.
Hello SEO enthusiasts! I appreciated this article. One can surely boost search visibility by buying sidebar backlinks from
virgool.io. If you want to rank better, contact me on Telegram @myd_80
or check out my SEO group @seoprem. Also, the magic of
internal seo is for mehran yousefi. Don’t forget, the best
telegram seo group is in this link: https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx. We provide guest posts for sale.
Hey everyone! This post helped me learn a lot. If you want to rank better, buy sidebar backlinks from virgool.io.
You can text me on Telegram @myd_80 or visit my SEO group
@seoprem. Remember, the magic of internal seo is for mehran yousefi,
and the best telegram seo group link is: https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx. We’ve also got guest posts for
sale.
Hey folks! This write-up gave me insights a lot.
If you want to rank better, get sidebar backlinks from virgool.io.
You can DM me on Telegram @myd_80 or check out my SEO group @seoprem.
Remember, the magic of internal seo is for mehran yousefi, and the best telegram seo group link
is: https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx. We’ve also got guest posts for sale.
Hi everyone! This content truly amazed me. I suggest you get sidebar backlinks from virgool.io.
If you want to rank better, contact me on Telegram @myd_80 or visit my SEO group
@seoprem. We have guest posts for sale. Also, the best telegram seo group
and the magic of internal seo is for mehran yousefi at https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx.
Hello SEO fans! This article was excellent. For better
SEO, purchase sidebar backlinks from virgool.io.
If you aim for better ranks, DM me on Telegram @myd_80 or stop by my SEO group @seoprem.
The best telegram seo group is there with mehran yousefi, plus the link:
https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx. We have guest
posts for sale.
Hello folks! I thoroughly enjoyed browsing this.
For top-notch SEO, buy sidebar backlinks from virgool.io.
If you want to rank better, text me on Telegram @myd_80 or visit my
SEO group @seoprem. Also, discover the best telegram seo group link at https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx. The magic of internal seo is for
mehran yousefi. We have guest posts too.
صبح بخير همه عزيزان، همين
خبر عجيب منو شيفته كرد. يه وبسايت خبري معتبر
پيدا كردم كه خبرهاي هيجانانگيز و دقيقي داره.
ميتوني يه نگاه بنداز تا اخبار بهروز رو ببيني.
سلام شما عزيزان، فوقالعاده اين محتوا بينظير بود.
يه پلتفرم خبري بينقص دارم كه اطلاعات تازه و
معتبري داره. اگه دنبال اخبار جذاب هستي، حتماً چك كن.
Hey everyone! This write-up gave me insights a lot.
If you want to rank better, obtain sidebar backlinks from virgool.io.
You can message me on Telegram @myd_80 or check out my SEO
group @seoprem. Remember, the magic of internal seo is for
mehran yousefi, and the best telegram seo group link is:
https://virgool.io/@yousefimehran2001/گروه-تلگرام-سئو-j7scgevxnkxx. We’ve
also got the best SEO backlinks services.
Terrific article! This is the kind of info that are meant to be shared across the web.
Disgrace on Google for now not positioning this post higher!
Come on over and consult with my website . Thanks =)
سلام دوستان همه دوستان، نمیتونم از
این بگذرم نوشته به وجد اومدم.
یه وبسایت خبری فوقالعاده دارم که خبرهای دقیق و تازه داره.
اگه دوست داری اخبار دقیق بخونی، برو ببین.
سلام عزيزان علاقهمندان، اين داستان فوقالعاده منو جذب كرد.
دارم يه وبسايت خبري عالي كه خبرهاي تازه و موثق داره.
يه نگاه بهش بنداز تا اخبار جديد رو از دست ندي.
خوش اومديد جامعه، ديوونهی كاوش
توي اين شدم بخش لذت بردم. يه پلتفرم
خبري شگفتانگيز دارم كه خبرهاش بهروز و جذابه.
اگه دوست داري اخبار دقيق بخوني، برو ببين.
You should be a part of a contest for one of the
finest sites online. I’m going to recommend this website!
link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi
link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi
link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link
porno grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno grafilink porno grafilink
porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno
grafi link porno grafilink porno grafilink porno grafi link porno grafilink
porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link
porno grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno
grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno
grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink
porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink
porno grafi link porno grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno grafilink
porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi
link porno grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno grafilink porno grafilink
porno grafi link porno grafilink porno grafilink porno grafi link
porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno
grafi link porno grafilink porno grafilink porno
grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink
porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi
link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink
porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link
porno grafilink porno grafilink porno grafi link porno
grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi link porno grafilink porno grafilink porno grafi
Pretty portion of content. I just stumbled upon your site and in accession capital to say that I acquire in fact enjoyed account your weblog posts.
Anyway I’ll be subscribing on your augment and even I achievement you get entry to persistently rapidly.
I’m impressed, I must say. Rarely do I encounter a blog that’s both educative and entertaining, and
let me tell you, you’ve hit the nail on the head.
The problem is something that not enough folks are speaking
intelligently about. Now i’m very happy that I came across this during my hunt for something
relating to this.
Wow, marvelous blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your website
is great, as well as the content!