【问题标题】:A potentially dangerous Request.Path in ASP.NET AjaxActionLink RequestASP.NET AjaxActionLink 请求中的潜在危险 Request.Path
【发布时间】:2015-06-11 14:48:30
【问题描述】:

我在 MVC ASP.NET 应用程序中有一个 cshtml 视图。我只想让用户单击一个按钮并在执行操作之前向用户提供警告。我知道实现我想要的唯一方法是像这样使用AjaxActionLink

<a role="button" 
   class="btn btn-lg btn-primary" 
   href='@Ajax.ActionLink(
        "Clear Invite Log",
        "ClearInviteLog",
        "Tools",
        null,
        new AjaxOptions { HttpMethod = "GET" },
        new { onclick = "return confirm('Are you sure you want to clear the invite log?');" })'>
    Clear Invite Log
</a>

我的控制器的名称是ToolsController,我发布到的方法是ClearInviteLog。问题是,当我单击按钮时,我没有得到警告对话框,而是得到 ​​p>

“/”应用程序中的服务器错误。 检测到来自客户端 (

堆栈跟踪: [HttpException (0x80004005): 从客户端检测到潜在危险的 Request.Path 值 (

我是 Web 开发的新手,我很困惑。我在这里做错了什么?

感谢您的宝贵时间。

【问题讨论】:

  • 为你的前端使用数据绑定库而不是 Razor 来自动生成你的东西,然后你会发现你会做更少的建模,并且遇到更少的问题
  • 检查这个问题,可能和你的一样stackoverflow.com/questions/5967103/…
  • 我已经阅读了这个问题。它和我的“不一样”。感谢您的宝贵时间。

标签: c# asp.net-mvc razor


【解决方案1】:

你不需要设置Ajax.ActionLink的锚标签href值,Ajax.ActionLink和Html.ActionLink本身会被渲染为锚标签,你只需要直接使用Ajax.ActilnLink:

@Ajax.ActionLink(
    "Clear Invite Log",
    "ClearInviteLog",
    "Tools",
    null,
    new AjaxOptions { HttpMethod = "GET" },
    new 
       { 
         onclick = "return confirm('Are you sure you want to clear the invite log?');",
         @class ="btn btn-lg btn-primary",
         role="button" })

【讨论】:

  • Ohhhhha,非常感谢您在这里的时间,非常感谢...我现在就试试这个。
猜你喜欢
  • 2011-03-07
  • 1970-01-01
  • 1970-01-01
  • 2014-07-30
  • 1970-01-01
  • 2012-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多