2012-10-31 58 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); 
    } 
}