12

每次我的 ASP.NET-Application 抛出错误时,我都在使用 Log4Net 并进行日志记录:

    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 上。

4

3 回答 3

22

我敢打赌,这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的情况,例如网络爬虫试图爬取您的网站。

于 2012-03-01T14:21:38.553 回答
0

我有同样的错误:

CSS中有一些文件引用。那在目录中不存在。所以它给出了这个错误。我创建了图像文件,所以错误消失了。

因此,请确保您提供的文件引用存在于您的目录中

于 2014-01-18T06:09:35.087 回答
0

检查页面的 HTML 输出,以防将 url 与 tilda "~/" 一起使用

您需要使用 @Url.Content() 来修复它

http://clubmicrosoft.net/post/2014/02/28/File-does-not-exist.aspx

于 2014-02-27T21:14:58.760 回答