ASP.NET MVC Custom Routing Long Custom Route not Clicking in my Head

不羁的心 提交于 2019-12-31 02:10:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/2982140/asp-net-mvc-custom-routing-long-custom-route-not-clicking-in-my-head

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!