Correct optional route parameters on browsing url

我们两清 提交于 2019-12-20 07:49:06

问题


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 },
);

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

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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/26648823/correct-optional-route-parameters-on-browsing-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!