.net - ASP.NET routing w/ changing article name -
is possible ignore second last part of url asp.net routing?
e.g. ../article-name-x/123456/
no matter how product name changes, point same article adding article id @ end , use point correct article.
we have product hasn't got it's final name yet on announcement, need update when final name known. used initial url in our communication , don't want link broken later.
can me out?
if understood question right want route have both article name , id.
you can use attribute routing
in .net mvc
. pass both name , id path parameters defined in route. in action can use 1 of them (or both) search article.
first allow attribute routing in registerroutes
method
routes.mapmvcattributeroutes();
then define route
attribute action
[routeprefix("articles")] [route("{action=index}")] public class articlescontroller : controller { // e.g /articles public actionresult index() { … } // e.g. /articles/my-article-name/my-article-id [route("{name}/{id}")] public actionresult search(string name, string id) { … } }
this action can called as
articles/my-article-name/my-article-id
please refer this article details.
hth.
Comments
Post a Comment