ASP.NET MVC 自定义路由 很长的自定义路由在我脑海中没有出现
今天我花了几个小时阅读有关在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您几乎可以使用路由做任何事情,但关键是知道以什么顺序注册它们。当 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.