2012-10-31 50 views
2

我在我的日志文件中看到数千个“[2012/10/31 16:08:23] FATAL: An unhandled error occurred. - Exception : A potentially dangerous Request.Path value was detected from the client (%).”。ASP.NET如何在异常发生时记录请求URL?

我认为有人正在使用攻击工具尝试邪恶请求。我无法在当地环境中重现它。

我在Global.asax中执行此日志,Application_Error事件。

protected void Application_Error(object sender, EventArgs e) 
{ 
    var ex = Server.GetLastError(); 
    if (null != ex) 
    { 
     Edi.Web.Logging.Logger.Fatal("An unhandled error occurred. ", ex); 
    } 
} 

但是我该如何记录这个危险的“Request.Path”的特定请求url呢?

(这不是好主意,登录的Application_BeginRequest每Request的,我只是想记录一个谁造成这个异常)

+1

只是为了添加更多信息,这是不太可能有人“攻击”您的应用程序。当在查询字符串中使用某些特殊字符并且您的应用程序可以通过在搜索查询中允许特殊字符来传递它们时引发此异常。查看[this](http://www.christophercrooker.com/use-any-characters-you-want-in-your-urls-with-aspnet-4-and-iis)了解更多信息 – tucaz

回答

1

希望,这是你想要什么:

protected void Application_Error(object sender, EventArgs e) 
{   
    var ex = Server.GetLastError(); 
    if (null != ex) 
    { 
     Edi.Web.Logging.Logger.Fatal("An unhandled error occurred. " + "---Page:" 
      + HttpContext.Current.Request.Url.ToString(), ex); 
    } 
}