Free ASP.NET Hosting Tips – Simple Ways to Manage Links Across ASP.NET MVC Website

When you first got into web development and developed your first web site, it was probably a simple 2 or 3 page site, probably static and a lot of links. If a page’s URL changes, you would have to change every link on every page that referenced that URL. That’s not cool!

images
So over the years, we’ve found a number of ways to lower your stress when managing your links across your 1000-page website. Here are the top ways to manage your links across your own ASP.NET MVC website:

1. Place Your Links in One Place

When I mean place your links in one location, I don’t mean place them into one HTML View. I mean logically partition your links in a Helpers\URL folder by class or, if you have a small web site, place them into one class for easy reference. When you’re asked to change a page’s location and that means touching hundreds of pages of links to change, you have to learn this tip!

2. Remove Your Url.ActionLinks from Your Views

We would say that 60% of every ASP.NET MVC application we’ve seen, a majority of people use the good old Url.ActionLink syntax when building their links on a View.

Instead of using Url.ActionLinks, replace them with:

Why? These are the reasons:

  1. It makes your HTML code more granular
  2. It makes your code more readable
  3. It makes your code compile-able with no “magic strings”
  4. It removes the human error factor from fat-fingering a link
  5. It refers back to tip 1 which implies that all links are in one centralized location.

3. Use #regions

I can just hear all of the developers groaning and moaning about regions, but I find them helpful when I have a large list of URLs that I can easily see at-a-glance where everything is located in the class. As I’ve said before, it’s like a table-of-contents for link management.

4. Use Url.RouteUrl whenever Possible

The Url.RouteUrl is the fastest generation of a Url in ASP.NET MVC. Period. There were tests done comparing the different types of link generation and Url.RouteUrl was the fastest out of all of them. We have seen it’s speed on a link directory web site we wrote back in 2012. After replacing the Url.ActionLink with Url.RouteUrl, there was a significant speed boost.

5. Overload Your UrlHelpers

There are times when you need to pass in an object as opposed to a string or integer, so why not use both. It doesn’t hurt to have both. So if you have a FAQ link like below:

There’s no harm in adding this one as well (so long as you need it):

So not only can you have a link that goes to your FAQ page, you can also have a link that goes to a FAQ number loaded from the ID as well. Here’s how you’d use it in the example below:

 6. Use Common UrlHelpers in Every Project.

If there are common links you use, place these UrlHelper routines in your scaffolding to speed up your development. For example, here’s one for a Root Url that will take you back to a main page:

We hope these tips above will make your link management a little easier on you when developing your ASP.NET MVC Web Site.

HostForLIFE.eu Free ASP.NET MVC Hosting

Try their Free ASP.NET MVC Hosting today and your account will be setup soon! You can also take advantage of their Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.

hostforlife banner