在 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/