如何在 "Production" 环境中 WebDeploy ASP.NET 核心应用程序?

How to WebDeploy an ASP.NET Core application in "Production" environment?

我创建了一个测试 ASP.NET 核心 Web 应用程序并通过 Web 部署将其发布到 Azure...

当我尝试通过站点 URL 访问页面控制器时,出现以下情况:

我默认主要是不修改 也是一个 lauchSettings.json 文件

{
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
            "applicationUrl": "http://localhost:23403/",
            "sslPort": 0
        }
    },
    "profiles": {
        "IIS Express": {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        },
        "IIS Express (Staging)": {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Staging"
            }
        },
        "IIS Express (Production)": {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Production"
            }
        },
        "MyApplication": {
            "commandName": "Project",
            "launchBrowser": true,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "applicationUrl": "http://localhost:23404"
        }
    }
}

我应该怎么做才能在发布时修改 ASPNETCORE_ENVIRONMENT 变量

PS.

我更新了 Azure 门户中的应用程序设置,就像这样 然后重新发布了应用程序...

但是什么都没变,我还是一样错误...

launchsettings.json 我认为只影响本地发展。它不会影响它在 Azure 中。我认为您应该能够定义一个应用程序设置,并将键 ASPNETCORE_ENVIRONMENT 设置为例如发展。

我认为你在这里混淆了 2 个问题。

  1. 部署到生产环境
  2. 监控错误

关于部署,看起来您做的一切都正确 - 您的站点不是使用开发环境托管的。这正是错误页面告诉您的内容。

关于错误,您绝对不希望任何人看到您的连接字符串或错误消息可能包含的任何其他内容。所以你需要添加一些日志记录来查看真正失败的地方。