手动创建参数ReturnUrl

发布于 2024-08-25 05:36:13 字数 534 浏览 3 评论 0原文

我有像“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘你却要生生世世 2024-09-01 05:36:13

您还可以使用Request.Url.AbsolutePath

<%= Html.ActionLink("enter to buy", "LogOn", "Account", 
    new { ReturnUrl = Request.Url.AbsolutePath })%>

You can also use Request.Url.AbsolutePath.

<%= Html.ActionLink("enter to buy", "LogOn", "Account", 
    new { ReturnUrl = Request.Url.AbsolutePath })%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文