.Net MVC:将路由值绑定到会话值
我想要执行以下操作:
用户应该在我的网站上有他自己的子网站。因此,我添加了一条新路由:
routes.MapRoute(
"ShopEntered",
"{username}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
当第一次调用站点时,我想将用户名值存储在会话中,然后将会话值绑定到路由的用户名部分,这样当我调用 Url.Action 时或 Html.ActionLink 我不必每次都手动设置它。
有谁知道我如何才能实现这一点?
I want to do the following:
The user should have his own sub site on my web site. Therefor I've added a new route:
routes.MapRoute(
"ShopEntered",
"{username}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
When the site gets called for the first time I want to store the username value in the session and then bind the session value to the username part of the route, so that when I call Url.Action or Html.ActionLink I don't have to set it every time manualy.
Does anyone know how I could realize this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法可能是编写自己的辅助方法并使用这些方法来代替
Html.ActionLink
和Url.Action
。例如:我不保证它无需修改即可工作,但您知道如何完成工作......
The easiest way would probably be to write your own helper methods and use these instead of
Html.ActionLink
andUrl.Action
. For example:I don't guarantee that it will work without modification, but you get the idea of how to do the work...