How to create SEO-enabled URLs in ASP.Net-MVC

I became acquainted with ASP.Net-MVC, and I tried to accomplish some common tasks that I have performed in the past with web forms and other functions. Regarding the most common tasks I need to do is create SEO-optimized URLs, which in the past meant doing some rewriting of URLs to create a query in the directory path.

e.g. www.somesite.com/productid/1234/widget

not: www.somesite.com?productid=1234&name=widget

What method do I use to accomplish this in ASP.Net-MVC?

I have a search, and all I found is that I either misunderstand or do not answer my question:

SEO URLs with ASP.NET MVC

+6
asp.net-mvc
source share
5 answers

Create a new route in Global.asax to handle this:

routes.MapRoute( "productId", // Route name "productId/{id}/{name}", // URL with parameters new { controller = "Home", action = "productId", id = 1234, name = widget } // Parameter defaults ); 

Asp.Net MVC has built-in routing, so there is no need for Url Rewriter.

+6
source share

MVC stands for β€œModel View Controller,” and although these concepts are not what you are asking for, you can usually plug in a URL, as you see above, pretty easily.

So, for example, the default URL is as follows

 http://www.somesite.com/controller/view/ 

where the controller belongs to the controller class in your project, and the view refers to the combination of pages / methods in the controller. So, for example, you could write a view to enter input and see something like the following

 http://www.somesite.com/widget/productid/1234/ 

Now, with regard to SEO Friendly URLs, it's just useless sugar. You create your controller in such a way that it adds a harmless crate to the end of the URL.

So, for example, you will notice that the following three ways to get this question give the same result:

How to create SEO-enabled URLs in ASP.Net-MVC

How to create SEO URLs in ASP.Net-MVC

How to create SEO URLs in ASP.Net-MVC

Stack overflow created its route values ​​so that the bit that occurs after the question identifier is not really needed.

So why is he there? To increase Google PageRank. Google PageRank relies on many things, the total amount of which is secret, but one of the things people have noticed is that, all things being equal, the URL for the descriptive URL is higher. Therefore, why does qaru use this text after the question number.

+10
source share

Be careful when implementing routes with names in them, you need to confirm that the name entering the system is correct, or you can damage your SEO ranking on the page by indicating that several URIs have the same content, or have configured proper canonical or if your controller sets the 301st when visiting the "wrong" URI.

The quick entry I made on the last solution can be found at:
http://mynameiscoffey.com/2010/12/19/seo-friendly-urls-in-asp-net-mvc/

Some information on canons:
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html

+3
source share

I think what you need is MVC Routing take a look at these

+2
source share

It is also important to handle legacy URLs. I have a database of old and new URLs and I redirect the following code:

  public class AspxCatchHandler : IHttpHandler, IRequiresSessionState { #region IHttpHandler Members public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { if (context.Request.Url.AbsolutePath.Contains("aspx") && !context.Request.Url.AbsolutePath.ToLower().Contains("default.aspx")) { string strurl = context.Request.Url.PathAndQuery.ToString(); string chrAction = ""; string chrDest = ""; try { DataTable dtRedirect = SqlFactory.Execute( ConfigurationManager.ConnectionStrings["emptum"].ConnectionString, "spGetRedirectAction", new SqlParameter[] { new SqlParameter("@chrURL", strurl) }, true); chrAction = dtRedirect.Rows[0]["chrAction"].ToString(); chrDest = dtRedirect.Rows[0]["chrDest"].ToString(); chrDest = context.Request.Url.Host.ToString() + "/" + chrDest; chrDest = "http://" + chrDest; if (string.IsNullOrEmpty(strurl)) context.Response.Redirect("~/"); } catch { chrDest = "/";// context.Request.Url.Host.ToString(); } context.Response.Clear(); context.Response.Status = "301 Moved Permanently"; context.Response.AddHeader("Location", chrDest); context.Response.End(); } else { string originalPath = context.Request.Path; HttpContext.Current.RewritePath("/", false); IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(HttpContext.Current); HttpContext.Current.RewritePath(originalPath, false); } } #endregion } 

hope this is helpful

+1
source share

All Articles