asp.net-mvc - ASP.NET MVC 登录 ReturnUrl 始终为 NULL?

标签 asp.net-mvc redirect authentication

在 ASP.NET MVC 中使用表单例份验证,当尝试重新登录站点时,它会将 ReturnUrl 参数放入查询字符串中。我的登录操作方法接受“returnUrl”字符串。然而,returnUrl 字符串似乎始终为空,即使它明显位于查询字符串中也是如此。关于为什么会出现这种情况或可能的解决方案有什么想法吗?

最佳答案

当您使用一种通用登录表单,但显式指定 Controller 和 ActionMethod(这会导致表单发布,但丢失查询字符串)时,往往会发生这种情况

为了澄清,这就是您的 BeginForm 中的代码应如下所示:

Html.BeginForm("LogOn", "Account", new { ReturnUrl = Request.QueryString["ReturnUrl"] })

EDIT: This is by design as RickAnd mentions in comments below. However it doesn't allow for the UI pattern of being deep in a site, clicking on LogOn, then returning to the page you were previously on, if it allows anonymous users. It's a commonly requested pattern. David Allen's approach to LogOff would also work nicely for a clean redirect at LogOn.

关于asp.net-mvc - ASP.NET MVC 登录 ReturnUrl 始终为 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/827905/

相关文章:

sql-server - ASP.NET 身份 2 到 3

.net - 如何在 MVC 中返回 XML 字符串作为操作结果

javascript - 如何从 Hub 中删除用户?

c# - 用于访问静态模型成员的 MVC razor 语法

安卓用户登录

azure - 如何将自定义属性传递到 Azure AD 应用程序中的重定向 URL?

perl - 使用多个驱动程序的 CGI 应用程序身份验证

forms - HTTP 302 重定向不携带 application/x-www-form-urlencoded

node.js - 如何知道我将被重定向到的网址? [nodejs] [node-fetch]

redirect - 如何让 nginx 代理停止重定向到 root?