ASP MVC 3 - 如何定义 url 基的动态值?
我想向 URL 的基础“显示”动态值,因此 URL 将如下所示:host.com/SOME_VALUE/{area}/{controller}/{action}。
因此,如果请求的 url 没有第一个值(动态值):host.com/{area}/{controller}/{action},则应该调用正确的操作,但是当呈现视图时(或者可能在重定向时)发生)正确的 url 应返回正确的第一个值。
此解决方案仅适用于在 url 中显示标识用户登录的指定值,例如用户名或公司名称,或与当前会话相关的任何其他值,该值不会用于限制对操作,因此两个网址都应该有效,并在同一会话上调用相同的操作:
host.com/{area}/{controller}/{action} host.com/some_value/{area}/{controller}/{action}
有什么建议吗?
I would like to "show" a dynamic value to the base of the URL, so the url would be like this: host.com/SOME_VALUE/{area}/{controller}/{action}.
So, if a url without the first value (the dynamic value) is requested: host.com/{area}/{controller}/{action} the correct action should be called but when a view is rendered (or maybe when a redirect occurs) the correct url should be returned with the correct first value.
This solution would be useful only to show in the url a specified value the identifies the user logon, like the username or maybe the company name, or any other value related to the current session, this value won't be used to restricts access to the actions, so the both urls should be valid and call the same action on then same session:
host.com/{area}/{controller}/{action}
host.com/some_value/{area}/{controller}/{action}
Any suggestions ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这完全未经测试,但我认为它会起作用...
当使用 somevalue 部分时,是否可以向 URL 添加额外的静态值?即host.com/users/some_value/area/controller/action。这将使路线映射变得简单,因为您所需要的只是:
This is completely untested but i'd have thought it would work...
Would it be possible to add an additional static value to the URL when the somevalue part is used? i.e. host.com/users/some_value/area/controller/action. It would make the route mapping simple as all you'd need is: