如何解决“System.Web.HttpException (0x80004005):文件不存在”?

发布于 2024-10-14 07:43:53 字数 1196 浏览 2 评论 0原文

如果这个问题已经在这个网站上得到解答,我深表歉意,我进行了搜索,但没有找到这个确切的场景。

我正在将 log4net 添加到 WCF 服务中。我在 Application_Error 事件中添加了一个处理程序,它在每个请求上捕获文件未找到错误。

我在网站上看到过这种情况,通常错误可以追溯到根目录中没有“favicon”文件,或者 css 样式表中引用的图像丢失。

然而,这是一个WCF服务,没有CSS样式表,并且在根目录中添加favicon并不能解决问题。

还有其他人有解决此问题的好方法吗?

一些线索:

  • 我还没有将其部署到真正的 IIS 服务器,我在本地运行它。
  • 当我在 Visual Studio 内的 DEBUG 中运行时,仅当我从 Web 浏览器(IE 或 Chrome)访问该服务时,不会发生该错误
  • 我将 url 和文件路径添加到错误消息中,这就是它们的内容是:

    URL: http://localhost:3994/

    文件路径: /

    错误: System.Web.HttpException (0x80004005):文件不存在。

编辑:以上值是在记录的异常中显示的值:

protected void Application_Error(object sender, EventArgs e)
{
    var objErr = Server.GetLastError().GetBaseException();
    if (objErr is System.Web.HttpException)
    {
        var filePath = Context.Request.FilePath;
        var url = ((HttpApplication) sender).Context.Request.Url;
        Log.Error("URL: " + url + "; FilePath: " + filePath, objErr);
    } else
        Log.Error("Application Error", objErr);
}

任何帮助将不胜感激。

Apologies if this has already been answered on this site, I searched but did not find this exact scenario.

I'm adding log4net to a WCF service. I added a handler in the Application_Error event, and it is catching a file not found error on every request.

I've seen this with web sites, and usually the error can be traced down to not having a "favicon" file in the root directory, or to a missing image referenced in a css stylesheet.

However, this is a WCF service, there is no CSS stylesheet, and adding a favicon to the root did not solve the problem.

Does anyone else have a good way to troubleshoot this?

Some clues:

  • I haven't deployed this yet to the real IIS server, I'm running it locally.
  • The error does not happen when I am running in DEBUG inside Visual Studio, only when I access the service from a web browser (IE or Chrome)
  • I added the url and file path to the error message, and this is what they are:

    URL: http://localhost:3994/

    FilePath: /

    Error: System.Web.HttpException (0x80004005): File does not exist.

Edit: the above values are what show up in the logged exception:

protected void Application_Error(object sender, EventArgs e)
{
    var objErr = Server.GetLastError().GetBaseException();
    if (objErr is System.Web.HttpException)
    {
        var filePath = Context.Request.FilePath;
        var url = ((HttpApplication) sender).Context.Request.Url;
        Log.Error("URL: " + url + "; FilePath: " + filePath, objErr);
    } else
        Log.Error("Application Error", objErr);
}

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜中书 2024-10-21 07:43:54

原因可能是未指定该服务。当 Web 服务器(也包括本地开发服务器)收到对文件夹的请求时,它们会在该文件夹中查找默认页面(通常称为:index.htm、index.html、default.asp、default.aspx 等)并呈现(除非您使用基于 REST 的服务描述)。当您从 VS 运行时,调试将直接带您进入实际服务。

在这种情况下,因为您已经构建了一个服务,所以您需要指定确切服务的位置,即 http://localhost:3994/service.svc

另外:如果您启动调试会话,然后将 URL 更改为 http://localhost:3994/,您应该能够通过调试器检查情况是否如此。

The reason is likely that the service has not been specified. When a web server (the local dev one as well) recieve a request for a folder they look inside that folder for the default page (usually called: index.htm, index.html, default.asp, default.aspx, etc) and present that (unless you are using a REST based service description). When you run from VS the debug will take you straight to the actual service.

In this case because you have built a service you need to specify the location of the exact service i.e. http://localhost:3994/service.svc.

Also: If you start a debug session and then change the URL to http://localhost:3994/ you should be able to check this is the case with the debugger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文