手动创建参数ReturnUrl
我有像“home/details/5”这样的视图,它可以由匿名用户访问。但有一个按钮,只有注册用户才能按下。没问题,我可以查看 Request.IsAuthenticated ,如果匿名,我会显示按钮登录而不是秘密按钮
,但问题是 - 当按登录时,我可能会丢失页面的地址和参数。如何创建登录按钮并传递参数 ReturnUrl ?就像
<%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = path to view with route value })%>
我只看到愚蠢的解决方案
<%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = "home/details/" + ViewContext.RouteData.Values["id"] })%>
,但我不喜欢对控制器的名称进行硬编码
i have view like 'home/details/5', it can be access by anonymous user. but there is button, which can be pressed only by registered users. no problem, i can look into Request.IsAuthenticated , and if anonymous i show button login instead of secret button
but the problem- when press login i can lose address and parameters of page. how can i create login button and pass a parameter ReturnUrl ? something like
<%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = path to view with route value })%>
i see only stupid solution
<%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = "home/details/" + ViewContext.RouteData.Values["id"] })%>
but i don't like to hard code names of controller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以使用
Request.Url.AbsolutePath
。You can also use
Request.Url.AbsolutePath
.