C# System.Web.HttpException文件不存在-页面加载正常(ASP.NET)

C# System.Web.HttpException文件不存在-页面加载正常(ASP.NET),c#,asp.net,exception,log4net,application-error,C#,Asp.net,Exception,Log4net,Application Error,每次ASP.NET应用程序抛出错误时,我都使用Log4Net并记录日志: protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); Log.Error("An error occurred", ex); } 唉,每次我访问应用程序上的页面时,都会捕捉到一个System.Web.HttpExcept

每次ASP.NET应用程序抛出错误时,我都使用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上。

我打赌Google Chrome总是请求的是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
的其他内容,例如,当网络爬虫试图对您的站点进行爬网时。

我有相同的错误:

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


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

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

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


Yep,favicon.ico或robots.txt。事实证明,Google Chrome总是请求的是
favicon.ico
,我忘了包括它。@DennisRöttger+1为什么我也会遇到这个错误,而我在使用Firefox时没有找到
favicon.ico
。不是铬。谢谢。这是一个很好的建议。我使用了HttpContext.Current.Request.Url而不是Request.RawUrl