簡體   English   中英

Visual Studio 2019 IIS 配置文件創建 web.config 文件,該文件破壞了 Azure 應用服務

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

在 ASP.NET 核心 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 服務器正在偵聽請求。錯誤 output 為:)) System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)

InvalidOperationException:NPM 腳本“start”退出,但未指示 create-react-app 服務器正在偵聽請求。 錯誤 output 是:Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(string sourcePath, string npmScriptName, ILogger logger)

我首先認為確切的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM