gpt4 book ai didi

asp.net-mvc - 使用查询字符串重定向

转载 作者:行者123 更新时间:2023-12-04 04:41:36 25 4
gpt4 key购买 nike

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

但是,如何向其附加查询字符串并仍然使用:

返回重定向(网址)?

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

最佳答案

试试这个,根据需要填写 Action 和 Controller 的名称:

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);

关于asp.net-mvc - 使用查询字符串重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com