【发布时间】:2011-12-31 18:32:47
【问题描述】:
我正在尝试将ReturnUrl 查询字符串传递到我的登录页面。我有一个部分登录视图(有点像登录框)和一个登录视图。现在,我的部分视图中有以下行:
using (Html.BeginForm("Login"
, "Account"
, new { returnUrl=HttpUtility.UrlEncode(
Request.QueryString["ReturnUrl"])
?? HttpUtility.UrlEncode(Request.Path)
}
, FormMethod.Post))
当我点击部分视图的提交按钮时(例如从
http://localhost:12345/Product/1234/Product1),
我将使用以下网址重定向到我的登录页面:
http://localhost:12345/Account/Login?returnUrl=%2FProduct%2F1234%2FProduct1
但如果我登录,我会看到一个 http 400 响应,因为页面正在返回
http://localhost:12345/Account/%2fProduct%2f1234%2fproduct1。
另外,如果我输入了错误的凭据,我会再次对returnUrl 查询字符串进行编码,因此每个% 字符都会再次转换为%25!
如果我手动输入,我应该提一下
http://localhost:12345/Account/Login?returnUrl=/Product/1234/Product1
(不带编码)并登录,成功重定向到指定路径。
我想我遗漏了一些明显的东西。但是查不出来是什么。
谢谢。
【问题讨论】:
-
编码不是自动为你完成的吗?你不需要自己编码。
标签: asp.net-mvc-3 authentication query-string urlencode returnurl