【问题标题】:ASP.NET Core page not found when publishing to IIS发布到 IIS 时找不到 ASP.NET Core 页面
【发布时间】:2016-07-13 06:12:04
【问题描述】:

我将我的 ASP.NET Core 项目从 RC1 更新到 1.0 RTM(使用 preview2 工具),一切正常。我可以在 Visual Studio 中毫无问题地进行调试。接下来我想在 Windows Server 2008 R2 和 IIS 7.5 上上传站点。我安装了必要的 Windows 托管工具并在 IIS 中创建了 Web 应用程序。问题是,在我尝试打开页面后,它返回了 404 错误。正如我在任务管理器中看到的,我的应用程序正在运行,但在侦听模式下停止。

在日志文件中我只看到这些条目:

Hosting environment: Production
Content root path: C:\inetpub\wwwroot\MySite
Now listening on: http://localhost:20706
Application started. Press Ctrl+C to shut down.

似乎 IIS 集成存在一些问题。我的web.config 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="..\..\approot\MySite\MySite.exe" arguments="" forwardWindowsAuthToken="true" stdoutLogEnabled="true" />
    <httpErrors errorMode="Detailed" />
  </system.webServer>
</configuration>

我从 GitHub 尝试了一些解决方法,但都影响了 Startup.cs 文件的 Configure 方法,但没有任何成功。

有什么想法吗?

【问题讨论】:

  • 您在 ASP.NET Core 模块日志 (stdoutLogFile) 中有什么?您可以添加 stdoutLogFile=".\logs\stdout" 以直接指定路径(在 web.config 中您已经有 stdoutLogEnabled="true")
  • 另外,如果您直接从发布文件夹运行应用程序,它可以工作吗?
  • 是的,应用程序在我直接启动时运行良好。我只有 IIS 有问题。
  • 您可以在此处找到故障排除步骤:blog.3d-logic.com/2016/06/08/…
  • 好的,谢谢,但很遗憾我没有找到任何新信息。 Web.config 和 project.json 看起来不错,并且链接没有提到任何关于错误 404 的内容。

标签: c# asp.net-core iis-7.5


【解决方案1】:

仅供参考.. app 文件夹中缺少此 web.config 文件。 该文件应位于:C:\wwwwroot\myapp\

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\XXX.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>
  </location>
</configuration>

不要忘记将 XXX.exe 替换为您的 Web API exe 名称的正确名称。

【讨论】:

    【解决方案2】:

    好的,我遇到了多个问题,但我的网站无法运行的主要原因有两个:

    1. 我无法从两个不同的地方开始代码。我最初将 wwwroot 的内容放在 wwwroot 文件夹下(并不那么令人惊讶),其余的放在 approot 下。现在所有内容都应该在同一个文件夹中。
    2. 我的发布版本不想工作。我必须使用调试文件夹的内容。我不知道为什么。

    现在,一切正常。

    【讨论】:

      猜你喜欢
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 2016-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多