ASP.NET MVC 捕获路由 url 的其余部分
我想了解如何在 ASP.NET MVC 中创建“捕获其余”路由?
我需要采用格式化的网址,读取一些数据到它的值,然后获取链接的其余部分并将其保存到某个变量,以便我稍后可以读取它并生成链接。
blog.mydomain.com/linker/process/2612010/2828/en/articles/october/asking-the-overflow/madd.aspx
内容如下:
会员ID = 2612010
会员评级 = 2828
语言 = en
restofurl =“articles/october/asking-the-overflow/madd.aspx”
或此链接:blog.mydomain.com/linker/process/2612010/2828/en/articles/october/read.aspx?m
=828 读起来像:
会员ID = 2612010
会员评级 = 2828
语言 = en
restofurl =“articles/october/read.aspx?m=828”
或
blog.mydomain.com/linker/process/2612010/2828/en/articles
至:
会员ID = 2612010
会员评级 = 2828
语言 = en
restofurl = "articles"
我考虑过类似的事情:
routes.MapRoute(
"Linker", // Route name
"Linker/Process/{memberid}/{memberrating}/{lang}/{*other}", // ULR with parameters
new { controller = "Linker", action = "Process", lang = "en", other = UrlParameter.Optional}
);
此路由正确拾取链接的其余部分,但在末尾省略 URL 参数: blog.mydomain.com/linker/process/2612010/2828/en/articles/october/read.aspx?m=828
并仅显示 articles/october/read.aspx
作为“restofurl”值。
我不需要经典的 url get params 分配给任何东西,只希望它们成为 restofurl 变量的一部分。
I would like to learn how do I make a "catch the rest" route in ASP.NET MVC?
I need to take formated urls, read some data to it's values, and take the remainder of the link and SAVE it to some variable so I can read it later and generate a link.
blog.mydomain.com/linker/process/2612010/2828/en/articles/october/asking-the-overflow/madd.aspx
read like:
memberid = 2612010
memberrating = 2828
language = en
restofurl = "articles/october/asking-the-overflow/madd.aspx"
or this link: blog.mydomain.com/linker/process/2612010/2828/en/articles/october/read.aspx?m=828
read like:
memberid = 2612010
memberrating = 2828
language = en
restofurl = "articles/october/read.aspx?m=828"
or
blog.mydomain.com/linker/process/2612010/2828/en/articles
to:
memberid = 2612010
memberrating = 2828
language = en
restofurl = "articles"
I've considered something like:
routes.MapRoute(
"Linker", // Route name
"Linker/Process/{memberid}/{memberrating}/{lang}/{*other}", // ULR with parameters
new { controller = "Linker", action = "Process", lang = "en", other = UrlParameter.Optional}
);
This route picks up the rest of the link correctly, but ommits URL parameters at the end of:
blog.mydomain.com/linker/process/2612010/2828/en/articles/october/read.aspx?m=828
and displays only
articles/october/read.aspx
as the "restofurl" value.
I don't need classic url get params assignet to anything, just want them part of the restofurl variable.
我自己来回答这个问题。
将有效构造一个正确的url。如果您碰巧找到一种“更干净/更好”的方法,请发帖。
I will answer this myself.
Will effectively construct a correct url. If you happen to find a "cleaner/nicer" way of doing it, please post.