ASP.Net Core MVC需要< environmentVariables>在web.config中工作 [英] ASP.Net Core MVC needs <environmentVariables> in web.config to work
问题描述
我正在将我的ASP.Net Core 3.1 MVC项目发布到IIS.该项目包括一个Web api控制器以及mvc控制器.它将生成一个web.config文件,如下所示.发布后,该应用会显示该页面,但除非添加<环境变量>指向发展.如果我改用Production,它将无法正常工作.
I am publishing my ASP.Net Core 3.1 MVC project to IIS. The project includes a web api controller along with mvc controllers. It generates a web.config file as below. Once published, the app shows the page but the web api doesn't work unless I add the < environmentVariables > pointing to Development. If I put Production instead, it doesn't work.
已生成Web.config
Web.config Generated
<?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=".\MyApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
修改了Web.config:
Web.config Modified:
<?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=".\MyApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
web.config的修改部分
Modified portion of web.config
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariables>
推荐答案
将Visual Studio更新到v16.6.3,该版本刚刚发布(6月30日).它显然包括针对此问题的修复程序.我只是遇到了类似的问题,发布在这里:
Update Visual Studio to v16.6.3, which was just release (June 30). It apparently includes a fix for this issue. I just went through this similar problem, posted here:
为什么会从launchSettings.json中获取环境变量是否存在aspNetCore web.config部分时无法加载配置文件?
这篇关于ASP.Net Core MVC需要< environmentVariables>在web.config中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!