我目前有一个登录链接在我的应用程序,看起来像这样:
<a href="/login?ReturnUrl=" + <%= Request.RawUrl %>>Login</a>
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(string returnUrl) { // Authenticate user return Redirect(returnUrl); }
这里的问题是如果RawUrl是具有多个url参数的东西,如“somepage?param1 = 1& param2 = 2& param3 = 3”,那么传递到登录操作的returnUrl将在第一个&符号“somepage? param1 = 1“。
我试过UrlEncoding的RawUrl,但似乎有什么区别。看来ASP.NET MVC框架这里是UrlDecoding url params在映射他们到控制器动作参数之前,这最终剥离了额外的url参数我想在我的returnUrl参数中看到。
有没有办法解决?我知道我可以只使用Request.Path并解析出我需要的值,但我想我会看看是否有一个更清洁的方法首先。
解决方法
您可能不正确地编码链接。是的,他们需要编码。这里是我们如何做:
<a href="<%= Url.Action("Delete","TimeRecord",new RouteValueDictionary(new { id = timeRecord.AltId,returnUrl=ViewContext.HttpContext.Request.Url.PathAndQuery }) ) %>">
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。