Cheap ASP.NET MVC 6 Hosting – How To Improve Your Website’s SEO In 3 Easy Steps

Cheap ASP.NET MVC 6 Hosting – How To Improve Your Website’s SEO In 3 Easy Steps

CheapASPNETHostingReview.com | Best and Cheap ASP.NET MVC 6 hosting review and comparison. Did you know that the default route of ASP.NET MVC will produce multiple URL’s that display the same content? And as I am sure you are aware, duplicate content can cause all sorts of SEO problems. In this post, I will show you three steps to prevent duplicate content with ASP.NET MVC 6.

1. Use attribute routing instead of the default route

Attribute Routing is a new feature added to ASP.NET MVC 6 that allows you to manually define each route by placing an attribute on each action.

Why use attribute routing?

Create a new ASP.NET MVC 6 application, and you will find the following URL’s all show the home page:

  • http://localhost
  • http://localhost/home
  • http://localhost/home/

Now I know, that it is unlikely that the search engine will discover the duplicate URL’s, but it is better to make sure only one can be accessed, and this can be done by using attribute routing.

Also, in my experience I have found that using attribute routing instead of the default route makes it easier to debug routing issues.

How to enable attribute routing?

  1. Remove the default route from your RouteConfig. Or even better, replace the default route with a catch all that points to an action that displays 404 not found.
  2. Enable Attribute routing by calling the routes.MapMvcAttributeRoutes() method in your RouteConfig class.
  3. Manually add the route to each action. For example, assigning [Route("")] to the index action of the home controller will fix the issue above.

2. Add or remove the trailing forward slash from your URL’s

There is still a slight issue. For example, with the following attribute applied to the about page:

The about page can be accessed using the following URL’s:

  • http://localhost/about
  • http://localhost/about/

You can fix this by adding a rewrite rule to your Web.config file. For example, the following rule will remove the trailing forward slash from all URL’s:

Just remember to set the AppendTrailingSlash to false in the RouteConfig class so that the routing system generates URL’s that have no trailing forward slash.

3. Redirect none www to www

It’s best practice to have either the www redirect to the none www or the www redirect to the www. For example, on this site cheapaspnethostingreview.com redirects to www.cheapaspnethostingreview.com This prevents duplicate content.

The following example shows a rewrite rule that redirect the none www to the www subdomain.

The other good thing about the rule above, is it will redirect all domains to the primary domain. For example, if you host your site on ASPHostPortal. The ASPHostPortal.com domain will be redirected to your main domain, preventing more duplicate content.