本文介绍了在浏览网址正确的可选路由参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作电子商务项目(Asp.Net MVC3)。我的产品和类别路由下面提到

I am working on Ecommerce project (Asp.Net Mvc3). My routes for product and categories are mentioned below

routes.MapLocalizedRoute(
  "Product",
  "p/{productId}/{SeName}",
   new { controller = "Catalog", action = "Product", SeName = UrlParameter.Optional },
);

routes.MapLocalizedRoute(
  "Product", 
  "c/{categoryId}/{SeName}",
  new { controller = "Catalog", action = "Category", SeName = UrlParameter.Optional },
);

在使用浏览网址 http://mysite.in/p/123/my-product 重定向到正确的产品,同样的事情发生的类别为好。

When use browse url http://mysite.in/p/123/my-product it redirects to correct product and same thing happens for category as well.

现在,当我从URL提供错误或SENAME只是删除SENAME重定向到正确的产品/类别,这是正确的。但我想有效SENAME要追加即如果有错,或在网址为SENAME产品repsective /类别没有SENAME应网址添加。是否有上述functinality的网站搜索引擎优化有任何影响。

Now when I provide wrong SeName or Just removes SeName from url it redirects to correct product/category, which is correct. But I want valid SeName to be appended i.e if there is wrong or no SeName in the url sename for repsective product/category should be added in url. Is there any effect on Site SEO of above functinality.

不#1同样认为,虽然即是SENAME可选择追加SENAME如果没有提供。

Stackoverflow does the same think i.e though SeName is optional it appends seName if not provided.

请回复,如果对同一问题有工作任何人。

Please reply if anybody having worked on same issue.

推荐答案

这是被称为塞,并在行动过滤器通常处理。菲尔哈克有一个很好的文章操纵动作方法参数解释得很详细。基本概念是处理过滤器 OnActionExecuting 法提取的 ID 参数的路径值,则查找从数据库中对应的名称和值添加到名称参数。

This is referred to as a 'slug' and is typically handled in an action filter. Phil Haack has a good article Manipulating Action Method Parameters that explains it in detail. The basic concept is to handle the filters OnActionExecuting method to extract the route value for the ID parameter, then look up the corresponding name from the database and add that value to the Name parameter.

这篇关于在浏览网址正确的可选路由参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!