asp.net MVC3 seo optimization: Use routing features to improve site weight _ practical skills

Source: Internet
Author: User
Tags lowercase

Brief introduction

One of the most important things we do when we develop Internet programs is SEO, and we all know that the ASP.net MVC program provides a friendly URL and permanent redirect support, and these friendly URLs are supported by the features of the routing system, But the problem with this routing is that there are several different addresses and the same action method, which means that your site has many addresses that are duplicated. This chapter will show you what to do if you solve this problem.

Body

For SEO, an address corresponding to a single independent content is to ensure the best weight of an important step, so we need to ensure that each URL address corresponding content is not duplicated (for MVC is the different action), but ASP.net MVC3 program default is problematic, For example, Homtcontroller.index This action method can be mapped to multiple addresses, such as:

1.http://abc.com (default)
2.http://abc.com/(trailing slash end)
3.http://abc.com/home (with Controller)
4.http://abc.com/home/action (with controller and Action)
5.http://abc.com/home/action (different situations)

Wait a minute

One way to solve this problem is to use the IIe URL Rewrite Extension, but it's very complex to configure, so here we use MVC's own features to solve this problem (by registering the global filter), add the following class:

public class Removeduplicatecontentattribute:actionfilterattribute
{public
  override void OnActionExecuting (ActionExecutingContext filtercontext)
  {
    var routes = routetable.routes;
    var requestcontext = Filtercontext.requestcontext;
    var routedata = Requestcontext.routedata;
    var datatokens = Routedata.datatokens;
    if (datatokens["area"] = = null)
      datatokens.add ("area", "");
    var VPD = routes. Getvirtualpathforarea (RequestContext, routedata.values);
    if (VPD!= null)
    {
      var virtualpath = vpd. Virtualpath.tolower ();
      var request = RequestContext.HttpContext.Request;
      if (!string. Equals (virtualpath, request. Path))
      {
        Filtercontext.result = new Redirectresult (virtualpath + request). Url.query, True);
      }
    Base. OnActionExecuting (Filtercontext);
  }


You can then register the filter in global:

public static void Registerglobalfilters (Globalfiltercollection filters)
{
  filters. ADD (New Handleerrorattribute ());
  Filters. ADD (New Removeduplicatecontentattribute ());
}

Let's explain:

First of all, removeduplicatecontent filter gets when my RequestContext and routedata, and then it's important to add a null value for Datatoken If you're not using area at the moment, Because if you do not add, then use the area feature after the words will be wrong.

The filter then obtains the virtual path via Routedata and then tolower to lowercase.

Then, comparing the path to the current request, if the inconsistency is redirected to a lowercase virtual path, then the search will be able to identify when multiple requests actually correspond to the real address of your virtual path, that is, the only address that corresponds to that action, In order to do one address corresponding to one content.

Summarize

For SEO, it is important to ensure that one address corresponds to one content, because if multiple addresses correspond to one content, search causes not knowing exactly which of your addresses is the latest and which is old, because it may reduce your weight.

Original English: Http://weblogs.asp.net/imranbaloch/archive/2011/12/19/solving-duplicate-content-issue-in-asp-net.aspx

The above article asp.net MVC3 seo optimization: The use of routing characteristics to improve the site is the weight of small parts to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.