【问题标题】:Visual Studio 2019 IIS profile creates web.config file that breaks Azure App ServiceVisual Studio 2019 IIS 配置文件创建破坏 Azure 应用服务的 web.config 文件
【发布时间】:2020-07-14 17:26:10
【问题描述】:

在 ASP.NET Core Web 3.1 项目上使用 Microsoft Visual Studio Community 2019 版本 16.6.3 创建新的调试配置文件时,会创建一个 web.config 文件。

文件如下所示:

<?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="C:\Users\<USER>\Source\Project\Project.Web\bin\Debug\netcoreapp3.1\Project.Web.exe" arguments="" stdoutLogEnabled="false" hostingModel="InProcess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

使用 web.config 访问站点时出现错误:

AggregateException:发生一个或多个错误。 (一个或多个错误 发生了。 (NPM 脚本 'start' 退出但没有表明 create-react-app 服务器正在监听请求。错误输出 是:)) System.Threading.Tasks.Task.ThrowIfExceptional(bool 包括任务取消异常)

InvalidOperationException:NPM 脚本“start”退出时没有 表明 create-react-app 服务器正在监听 要求。错误输出是: Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(字符串 sourcePath, string npmScriptName, ILogger logger)

【问题讨论】:

    标签: c# azure asp.net-core web-config


    【解决方案1】:

    我最初认为确切的aspNetCore processPath 是罪魁祸首,但考虑到错误,它看起来更像来自Startup.cs 的代码。

    if (env.IsDevelopment())
    {
        spa.UseReactDevelopmentServer(npmScript: "start");
    }
    

    查看实际部署的文件证实了我的怀疑,这里的路径是相对的。

    我需要将ASPNETCORE_ENVIRONMENT 设置为Production。通过创建一个新的web.release.config 文件解决了这个问题,因为我需要在实际 IIS 上使用ASPNETCORE_ENVIRONMENT 作为Development 测试应用程序。有了这种转变,一切都奏效了:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    
      <!-- To customize the asp.net core module uncomment and edit the following section. 
      For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
      <!--
      <system.webServer>
        <handlers>
          <remove name="aspNetCore"/>
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
        </handlers>
        <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
      </system.webServer>
      -->
    
      <location>
        <system.webServer>
          <aspNetCore>
            <environmentVariables>
              <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" xdt:Locator="Match(name)" xdt:Transform="SetAttributes" />
            </environmentVariables>
          </aspNetCore>
        </system.webServer>
      </location>
    
    </configuration>
    

    来源:

    https://stackoverflow.com/a/54702411/3850405

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-17
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多