我正在使用 Log4Net 并在我的 ASP.NET 应用程序每次抛出错误时进行记录:
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
Log.Error("An error occurred", ex);
}
唉,每次我访问我的应用程序的页面时,都会捕获到 System.Web.HttpException
,“文件不存在”。
这是堆栈跟踪:
bei System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
bei System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
bei System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
bei System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我不知道如何调试它,这发生在我的 ASP.NET 开发服务器和我部署它的 IIS 7.5 上。
最佳答案
我敢打赌它是谷歌浏览器总是请求的 favicon.ico
,但你忘记了包含它。但为了确保您可以跟踪请求 url:
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
Log.Error("An error occurred", ex);
Log.Error("Requested url: ", Request.RawUrl);
}
现在在您的日志文件中您应该看到:
Requested url: /favicon.ico
或其他类似 robots.txt
的东西,例如当网络爬虫试图抓取您的网站时。
关于c# - System.Web.HttpException 文件不存在 - 页面加载正常 (ASP.NET),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9517801/