Deploying a plain ASP.NET Core 2.2 Web App in Azure using Web Deploy is throwing an error

后端 未结 4 922
再見小時候
再見小時候 2021-01-04 13:42

I went to publish an ASP.NET Core web application using Azure through the Publish screen in Visual Studio 2017. I used all of the defaults, though my app uses migra

相关标签:
4条回答
  • 2021-01-04 13:56

    I deployed an AspNet Core 3.0 website to Azure and received an HTTP 500 server error.

    This was in the web.config:

    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\BedtimeWeb.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>
    

    I changed AspNetCoreModuleV2 to AspNetCoreModule and then the error became HTTP 502.3.

    I then removed the hostingModel="InProcess" attribute and the website then started working correctly.

    0 讨论(0)
  • 2021-01-04 14:01

    One easy solution would be to put the azure-db connectionstring in the appsettings.json instead of the appsettings.Development.json.

    When running the default generated asp.net core application in VS2017, you can find the launchSettings.Json file in the Properties folder with the profiles which will be run locally. There, under the profiles section you can see that the ASPNETCORE_ENVIRONMENT property is set to Development.

    "WebApp": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
    

    This means that if you define the local db connectionstring in your appsettings.Development.json it will use its connectionstring when running locally.

    If you don't define the ASPNETCORE_ENVIRONMENT property then the runtime will only use the appsettings.json values (Runtime will set the ASPNETCORE_ENVIRONMENT to Production as default but if you don't have any appsettings.Production.json defined then only the values in appSettings.json will be used).

    So when running the Azure Web App you don't need to specify the ASPNETCORE_ENVIRONMENT at all if you put the azure-db connectionstring in the appsettings.json.

    0 讨论(0)
  • 2021-01-04 14:06

    You can check and set your app settings and connection strings in Application settings section of you service:

    0 讨论(0)
  • 2021-01-04 14:16

    By default ASP.NET Core 2.2 apps are configured to use the new In Process hosting model. This will not be available on Azure in all regions until sometime in December 2018. They mention it here.

    The solution for now is to add the following at the top of your web app's .csproj file:

      <PropertyGroup>
        <AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
        <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
      </PropertyGroup>
    
    0 讨论(0)
提交回复
热议问题