2

我有某种情况,如果提供了 Returnurl,控制器中的 ActionResult 方法需要执行重定向。

但是,我怎样才能将查询字符串附加到它并仍然使用:

返回重定向(网址)?

每次我这样做时,我总是得到一个安全异常,即请求具有潜在的危险值(与号甚至问号)。

4

2 回答 2

4

试试这个,根据需要填写动作和控制器的名称:

System.Web.Routing.RouteValueDictionary rvd = new System.Web.Routing.RouteValueDictionary();
foreach(string key in HttpContext.Request.QueryString.AllKeys)
{
    rvd.Add(key, HttpContext.Request.QueryString[key]);
}

return RedirectToAction("MyAction", "MyController", rvd);
于 2013-09-13T20:54:10.620 回答
-1

忘记了 - 我使用了 Url.Content,现在它工作得很好。

返回重定向(Url.Content(model.ReturnUrl + otherPotentialQueryStringHere)

于 2013-09-13T20:19:11.793 回答