发布到IIS ASP.NET Core 3.1

问题描述

我有一个ASP.NET 3.1项目,已发布到Windows服务器。当我在计算机上本地运行项目时,它可以正常运行;但是,当我将远程桌面访问该Windows服务器时,在“网络”标签中出现500错误,并且出现以下错误

enter image description here

我已在我的Launch.json文件中将环境变量更改为Development,但仍然收到相同的错误

 "IIS Express": {
      "commandName": "IISExpress","launchbrowser": true,"environmentvariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }

当我在Windows事件查看器中查看时,发现此错误

enter image description here

有人可以帮我弄清楚这是怎么回事吗?

解决方法

请检查ASPNETCORE_ENVIRONMENT变量的值。您必须将此环境变量设置为“生产”(或“开发”以外的其他环境)。

否则,您可以像这样更新web.config:

<configuration>
 <system.webServer>
    <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\Application.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
        <environmentVariables>
            <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
        </environmentVariables>
    </aspNetCore>
 </system.webServer>
</configuration>

请参阅此post,以获取更多详细信息。