【问题标题】:System.Web.HttpException File does not exist - Page loads just fine (ASP.NET)System.Web.HttpException 文件不存在 - 页面加载正常(ASP.NET)
【发布时间】:2012-03-20 00:59:53
【问题描述】:

我正在使用 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 上。

【问题讨论】:

    标签: c# asp.net exception log4net application-error


    【解决方案1】:

    我敢打赌,它是 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 的东西,例如网络爬虫试图爬取您的网站。

    【讨论】:

    • 是的,favicon.ico 或 robots.txt。
    • 事实证明,谷歌浏览器总是请求favicon.ico,但我忘记包含了。
    • @DennisRöttger +1 为什么我也遇到了这个错误,没有找到favicon.ico我使用的是 Firefox。不是铬。谢谢。
    • 这是一个不错的提示。我使用 HttpContext.Current.Request.Url 而不是 Request.RawUrl
    【解决方案2】:

    我有同样的错误:

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

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

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-09
        • 1970-01-01
        • 2014-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-10
        相关资源
        最近更新 更多