asp.net - 如何显示更好的错误然后:"A potentially dangerous Request.Form value was detected from the client"

标签 asp.net error-handling security asp.net-mvc

在我自己的网站上进行一些黑客攻击时,我(在经过一些谷歌搜索后)遇到了一个常见问题。

“从客户端检测到潜在的危险Request.Form值,可能是XSS尝试或恶意字符

情况1:A potentially dangerous Request.Form value was detected from the client (Firstname ="<script> alert("x");...").
情况2:A potentially dangerous Request.Form value was detected from the client (*).

asp mvc团队为我捕获了错误,但表现出色,但是如何向用户显示更好的错误。例如“发生了什么事,请重复您的步骤,如果再次出现此消息,请与x人联系……”。

适用于ASP MVC开发人员的解决方案。

  • 使用索引
  • 创建一个ErrorController
  • 将以下行添加到您的web.config中:

  • <customErrors mode="On" defaultRedirect="~/Error/Index"/>


  • 编写测试以检查 Controller 的操作。
  • 不要忘记创建实际的 View 。

  • 可选,您可能需要将mode =“RemoteOnly”放进去

    有关CustomErrors属性的更多信息,请注意:customErrors Element

    最佳答案

    它不是特定于MVC的。 ASP.Net Web表单会给您同样的错误。

    我认为您应该使用“自定义错误页面”。自定义错误页面在Web.config中定义,如下所示:

    <customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx"/>
    

    有关自定义错误页面的更多信息,请访问http://aspnetresources.com/articles/CustomErrorPages

    另外,您可以处理Global.asax Application_Error事件以执行所需的任何操作。

    微软有一篇非常不错的文章,其中包括源代码,它确实可以完成您想要做的事情(以及更多)。在http://support.microsoft.com/kb/306355上查看

    关于asp.net - 如何显示更好的错误然后:"A potentially dangerous Request.Form value was detected from the client",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5469959/

    相关文章:

    javascript - 如何使 JavaScript cookie 可用于整个 ASP.NET Web 应用程序

    Asp.Net Mvc 复选框列表

    ajax - 与部分 View 并行的ASP.NET MVC AJAX调用返回错误消息

    asp.net - 如何在 asp.net 应用程序中定义一个实体,例如 nbsp

    ios - TensorFlow for Mobile Poets x86_64编译失败

    sql - 在ESQL中验证结果

    在传输之前Java解码编码的LDAP过滤器?防止 LDAP 注入(inject)

    api - preload.js 中的 ipcRenderer.on 如何检测 webContents.send?

    java - 使用 amazon elb 后面的 java 服务器重定向到 http 和 https 以及从 http 和 https 重定向

    asp.net - asp.net session 信息是否存储在cookie中?