Asp.net 为什么在重定向时使用包含问号的URL会得到“;潜在危险请求”;?
我正在使用MVC3,在我看来,我有以下代码块Asp.net 为什么在重定向时使用包含问号的URL会得到“;潜在危险请求”;?,asp.net,asp.net-mvc-3,Asp.net,Asp.net Mvc 3,我正在使用MVC3,在我看来,我有以下代码块 Response.Redirect(@Url.Action("index","home", new {error = "test"})); 所以我期望的url是,但我得到的是,这样我就得到了潜在的危险请求 有没有人有同样的问题,可以告诉我我做错了什么 更新: 我将逻辑移到控制器方法中,如下所示 public ActionResult Index() { if (!User.Identity.IsAuthenticated)
Response.Redirect(@Url.Action("index","home", new {error = "test"}));
所以我期望的url是,但我得到的是,这样我就得到了潜在的危险请求
有没有人有同样的问题,可以告诉我我做错了什么
更新:
我将逻辑移到控制器方法中,如下所示
public ActionResult Index()
{
if (!User.Identity.IsAuthenticated)
return RedirectToAction("index", "home", new { error = "test" });
return View();
}
它仍然重定向到http://marketurk.co.uk/%3Ferror=test我想说,这是典型的逻辑,会进入控制器。有一条永远存在的不成文的规则,你的观点应该包含尽可能少的逻辑,除非它是为了表达的目的 在控制器操作中,可以验证视图模型,如果视图模型无效,则应使用内置的RedirectToAction:
public ActionResult SomeAction()
{
// build your viewmodel here //
if(/* viewmodel is invalid */)
return RedirectToAction("index", "Home", new { error = "test" });
else
return View( /* your viewmodel */);
}
这是典型的逻辑,我会说,这将进入控制器。有一条永远存在的不成文的规则,你的观点应该包含尽可能少的逻辑,除非它是为了表达的目的 在控制器操作中,可以验证视图模型,如果视图模型无效,则应使用内置的RedirectToAction:
public ActionResult SomeAction()
{
// build your viewmodel here //
if(/* viewmodel is invalid */)
return RedirectToAction("index", "Home", new { error = "test" });
else
return View( /* your viewmodel */);
}
答案应该是:
作为
?
编码为%3F
,
通过使用Html.Raw
您可以保留?
Response.Redirect(Html.Raw(Url.Action("index","home", new {error = "test"})));
答案应该是:
作为
?
编码为%3F
,
通过使用Html.Raw
您可以保留?
Response.Redirect(Html.Raw(Url.Action("index","home", new {error = "test"})));
您是否正在为该控制器使用OnActionExecuting函数?问题可能是由您请求后的另一行代码引起的?您是否为该控制器使用OnActionExecuting函数?可能是您请求后的另一行代码导致的问题?这一行@Url.Action(“index”,“home”,new{error=“test”})在重定向之外生成了什么?这一行@Url.Action(“index”,“home”,new{error=“test”})生成了什么是否在重定向之外生成?我已经这样做了,它仍然重定向到包含%3F的同一url。我已经这样做了,它仍然重定向到包含%3F的同一url