ASP.NET MVC 捕获路由 url 的其余部分

发布于 10-14 22:05 字数 1302 浏览 5 评论 0原文

我想了解如何在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演出会有结束2024-10-21 22:05:57

我自己来回答这个问题。

var restofurl =
String.Format("{0}?{1}", RouteData.Values["other"], Request.QueryString);

将有效构造一个正确的url。如果您碰巧找到一种“更干净/更好”的方法,请发帖。

I will answer this myself.

var restofurl =
String.Format("{0}?{1}", RouteData.Values["other"], Request.QueryString);

Will effectively construct a correct url. If you happen to find a "cleaner/nicer" way of doing it, please post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文