简体   繁体   English

Visual Studio 2019 IIS 配置文件创建 web.config 文件,该文件破坏了 Azure 应用服务

[英]Visual Studio 2019 IIS profile creates web.config file that breaks Azure App Service

When creating a new Debug profile with Microsoft Visual Studio Community 2019 Version 16.6.3 on a ASP.NET Core Web 3.1 project a web.config file is created.在 ASP.NET 核心 Web 3.1 项目上使用 Microsoft Visual Studio Community 2019 版本 16.6.3 创建新的调试配置文件时,将创建web.config文件。

在此处输入图像描述

The file looks like this:该文件如下所示:

<?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>

Errors present when accessing the site with web.config:使用 web.config 访问站点时出现错误:

AggregateException: One or more errors occurred. AggregateException:发生一个或多个错误。 (One or more errors occurred. (The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. The error output was: )) System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions) (发生了一个或多个错误。(NPM 脚本“start”退出,但未指示 create-react-app 服务器正在侦听请求。错误 output 为:)) System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)

InvalidOperationException: The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. InvalidOperationException:NPM 脚本“start”退出,但未指示 create-react-app 服务器正在侦听请求。 The error output was: Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(string sourcePath, string npmScriptName, ILogger logger)错误 output 是:Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(string sourcePath, string npmScriptName, ILogger logger)

I first thought that the exact aspNetCore processPath was the culprit but given the error it more looked like code from Startup.cs .我首先认为确切的aspNetCore processPath是罪魁祸首,但考虑到错误,它更像来自Startup.cs的代码。

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

Looking at the actual file deployed it confirmed my suspicions, the path was relative here.查看部署的实际文件证实了我的怀疑,这里的路径是相对的。

在此处输入图像描述

I needed to set ASPNETCORE_ENVIRONMENT as Production .我需要将ASPNETCORE_ENVIRONMENT设置为Production Solved this by creating a new web.release.config file since I needed to test the application on an actual IIS with ASPNETCORE_ENVIRONMENT as Development .通过创建一个新的web.release.config文件解决了这个问题,因为我需要在实际的 IIS 上测试应用程序,并使用ASPNETCORE_ENVIRONMENT作为Development With this transformation everything worked:通过这种转换,一切正常:

<?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>

Source:资源:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio Web 2013 中添加 app.config 或 web.config 文件? - How can I add an app.config or web.config file in Visual Studio Web 2013? Web.config 用于 .net 部署到 Azure 应用服务 - Web.config for .net deployment to Azure app service Azure 应用服务无法从 visual studio 2019 发布 - Azure App service cannot publish from visual studio 2019 在Visual Studio 2015中将web.config不是app.config发布到xxx.dll.config - web.config not app.config being published to xxx.dll.config in Visual Studio 2015 Visual Studio Web.Config转换 - Visual Studio Web.Config Transform Visual Studio 中特定于开发人员的 app.config/web.config 文件 - Developer specific app.config/web.config files in Visual Studio 配置(app.config或web.config)在Visual Studio 2012中未显示智能感知 - configuration(app.config or web.config) is not showing intellisense in visual studio 2012 我们可以使用WinRM更新web.config文件 - IIS Web App部署任务 - can we update the web.config file using WinRM - IIS Web App Deployment Task 有没有一种方法可以将web.config配置文件属性与外部配置文件合并? - Is there a way to merge web.config profile properties with an external config file? 尝试从Windows服务读取IIS站点的web.config文件 - Trying to read web.config file for an IIS site from a Windows service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM