ASP.NET MVC 自定义路由 很长的自定义路由在我脑海中没有出现

发布于 2024-09-04 08:17:17 字数 532 浏览 2 评论 0原文

今天我花了几个小时阅读有关在 ASP.NET MVC 中进行自定义路由的内容。我可以理解如何执行任何类型的自定义路由(如果它从默认路由扩展或类似于/小于默认路由)。但是,我正在尝试弄清楚如何执行类似于以下内容的路线:

/Language/{LanguageID}/Question/{QuestionID}/

我也想要类似于 SO 的工作方式。例如:

/Language/{LanguageID}/Arabic/Question/{QuestionID}/Some-Question-Title

“阿拉伯语”和“某些问题标题”几乎可以是任何内容,因为真正重要的是 ID

完整的 url 示例可能是

http://example.com/Language/22/Arabic/Question/135/What-is-the-importance-of-grammar

我是否超出了语言 ID 之外的扩展 URL 所能完成的范围?

I have spent several hours today reading up on doing Custom Routing in ASP.NET MVC. I can understand how to do any type of custom route if it expands from or is similar/smaller than the Default Route. However, I am trying figure out how to do a route similar to:

/Language/{LanguageID}/Question/{QuestionID}/

And what I would like, too, is similar to how SO works. Something like:

/Language/{LanguageID}/Arabic/Question/{QuestionID}/Some-Question-Title

Where "Arabic" and "Some-Question-Title" can be almost anything because what really matters is the ID's

A complete url example might be

http://example.com/Language/22/Arabic/Question/135/What-is-the-importance-of-grammar

Am I going beyond what can be done with the extended URL past the language ID?

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

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

发布评论

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

评论(1

泅人 2024-09-11 08:17:17

您几乎可以使用路由做任何事情,但关键是知道以什么顺序注册它们。当 MVC 选择路由时,它会按照注册的顺序进行操作,并且第一个匹配的路由就是被选择的路由。

You can pretty much do anything with routes, but the key is knowing in which order to register them. When MVC selects a route, it does so in order in which they were registered, and the first route that matches, is the one that is selected.

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