c# - Visual Studio 2019 IIS 配置文件创建破坏 Azure 应用服务的 web.config 文件
问题描述
在 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 脚本“启动”退出,但未指示 create-react-app 服务器正在侦听请求。错误输出为:)) System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)
InvalidOperationException:NPM 脚本“启动”退出,但未指示 create-react-app 服务器正在侦听请求。错误输出是: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
as测试应用程序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>
资源:
推荐阅读
- python-3.x - 尝试构建调度应用程序,我应该学习什么?
- heroku - heroku 重定向到文件,同时隐藏 url
- python - Discord bot 删除用户的所有消息
- google-sheets - 当函数在我的数据源中以不同方式显示时,如何在函数中引用 URL?
- c# - OLEDBConnection:将字节 [] 插入 blob 不会保存更改
- scala - 如何在 Streamsets 中使用 Scala 或 Pyspark 使用 Apache Spark 进行机器学习?
- git - 没有 Github 操作的单推
- matlab - 我需要在 ubuntu 20.04 上安装 gcc4.9 | matlab 墨西哥
- sql-server - 失去与映射网络驱动器的连接后恢复远程数据库
- ios - 如何让我在 iOS 14 上运行的 PWA 使用浏览器发起的会话?