代码改变世界

微软ASP.NET 最新漏洞的解决方案

2010-09-21 11:03  音乐让我说  阅读(339)  评论(0编辑  收藏  举报

在web.config 中配置:

 

<configuration>

   <system.web>

     <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/error.aspx" />

   </system.web>

</configuration>

 

其中 ASP.NET V3.5SP1 以下版本没有 属性“redirectMode”,所以可以不用配置。

 

error.aspx 页面代码如下:

 

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Threading" %>

<script runat="server">
   void Page_Load() {
      byte[] delay = new byte[1];
      RandomNumberGenerator prng = new RNGCryptoServiceProvider();

      prng.GetBytes(delay);
      Thread.Sleep((int)delay[0]);
        
      IDisposable disposable = prng as IDisposable;
      if (disposable != null) { disposable.Dispose(); }
    }
</script>
<html>
<head runat="server">
    <title>Error</title>
</head>
<body>
    <div>
        抱歉,访问出错!
    </div>
</body>
</html>

 

直接放在网站根目录,可以不用编译。

参考了 http://weblogs.asp.net/scottgu/archive/2010/09/18/important-asp-net-security-vulnerability.aspx

 

谢谢浏览!