ASP.NET MVC URL 生成扩展点

发布于 2024-08-22 01:24:58 字数 264 浏览 3 评论 0原文

ASP.NET MVC 中 URL 生成的扩展点有哪些?

  1. 路由 - 虚拟路径取决于它
  2. ???

附录1
特别是,我不仅需要控制 URL 的路径部分,还需要控制主机。我想将我的生成逻辑嵌入到 MVC 框架中,以便对标准 Html.ActionLink 方法的任何调用都将涉及我的逻辑。那将是完美的。然而,在调查 MVC 来源时,我迫切希望通过一种简单的方法来实现我的目标。

What are extensibility points of URL generation in ASP.NET MVC?

  1. Routes - virtual path depends on it
  2. ???

Addendum 1
Particularily, I need to control not only path part of URL but the host also. And I'd like to embed my generation logics into MVC Framework so that any call to standard Html.ActionLink method would involve my logics. It would be perfect. However, investigating MVC sources I'm desperate to achieve my goal with an easy way.

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

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

发布评论

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

评论(3

冷了相思 2024-08-29 01:24:58

路线几乎就在它所在的地方。但请记住,您可以子类化 Route 并提供您自己的不使用键/值 URI 模板的实现。

没有什么可以阻止您从头开始编写自己的解决方案,但这没有多大意义,因为已经有一个可扩展的基础可供您使用。

Routes is pretty much where it's at. Remember, though, that you can subclass Route and provide your own implementation that does not use key/value URI templates.

There's nothing stopping you from writing your own solution from the ground up, but there's not much point since there's already an extensible foundation for you to work with.

故事未完 2024-08-29 01:24:58

路由扩展点

  • 路由
  • 路由约束
  • 路由处理程序

在您的特定情况下,您必须编写自己的路由来填充与主机相关的其他 RouteData 项。解析您的 URL 将完全由您负责。

“{host}/{controller}/{action}”

也许还可以创建自定义路由处理程序,使主机参数成为强制参数。但这已经取决于您的特定需求。

编辑

我猜这篇关于域路由的文章< /a> 可能对你有帮助。它看起来相当直接且简单。

Routing extensibility points

  • Routes
  • Route constraints
  • Route handlers

In your particular case, you will have to write your own route that will populate additional RouteData items related to host. Parsing your URL will be totally on you.

"{host}/{controller}/{action}"

Maybe also create your custom route handler that will make host parameter mandatory. But that already depends on your particular needs.

Edit

I guess that this article about domain routing may be of some help to you. It looks preety straight forward and uncompicated.

寻找我们的幸福 2024-08-29 01:24:58

事实上,由于 Route 在 URL 生成过程中仅提供 VirtualPath 部分,因此不可能达到所需的灵活性。

Indeed, it's impossible to reach desired flexibility since Route gives just VirtualPath portion during URL generation.

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