Can have part of the domain name as a parameter in my routing rules?

余生颓废 提交于 2019-12-06 10:00:23

问题


I'd like to have a routing rule that accepted part of my domain name as a parameter. For example:

{name}.mydomain.com/photos/{id}

Is this even possible?


回答1:


I have had a similar issue in using asp.net mvc, but with using the whole domain instead of just the subdomain. What we used was a custom route constraint to determine which controller to go to (domain determined controller on our project). Then in the controller we used the normal asp.net request.url properties to take an action. This may or may not help depending on your exact requirements.




回答2:


It wouldn't be possible since the {name}.mydomain (a valid name instead of {name}) is the Authority part of a Uri. The routing can be performed only on the PathAndQuery part of a Uri.

Edit: I was somehow wrong, take a look at this answer: Manipulating Url structure




回答3:


See ASP.NET MVC Domain Routing by Maarten Balliauw.



来源:https://stackoverflow.com/questions/490963/can-have-part-of-the-domain-name-as-a-parameter-in-my-routing-rules

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