12

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 migrations so I had to tell it to run them in the publish profile.

When I try to access the site, however, I get:

The page cannot be displayed because an internal server error has occurred.

I feel like there is something I need to do with the connection string and the ASPNETCORE_ENVIRONMENT variable.

I still have the default appsettings.json and appsettings.Development.jsonthat you get when creating a new ASP.NET Core web app. The appsettings.json is pointing to my local development database, and the appsettings.Development.json is pointing to the Azure database from the publish profile.

Or does the publish profile automatically take care of the connection string and I don't have to do any of the above?

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231

4 Answers4

24

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>
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
1

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

enter image description here

Michael
  • 1,027
  • 10
  • 22
  • I noticed this. I was wondering it it might have been the cause of my error. But in this https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-webapp-using-vs?view=aspnetcore-2.2 they don't do anything with environment variables so I am assuming the publish profile takes care of it. Any idea how I can troubleshoot the error? Are there logs anymore? It is so strange the database is getting created, so is the schema, but my seed function in program.cs must not be running or erroring because there is no data. – Blake Rivell Dec 11 '18 at 18:23
  • There is a `log stream` which reads an app logs but it should be enabled first. You can also try to enable `Remote Debugging` in `Application Settings` and debug with your VS. – Michael Dec 11 '18 at 18:27
  • Enabling logs: https://learn.microsoft.com/en-us/azure/app-service/web-sites-enable-diagnostic-log#enablediag You can also find locations in a next section of the doc. – Michael Dec 11 '18 at 18:29
  • with logging I found my error: Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list. I think it has something to do with: InProcess in .net core 2.2 – Blake Rivell Dec 11 '18 at 18:53
1

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.

Marcus Höglund
  • 16,172
  • 11
  • 47
  • 69
  • 1
    Alright, I will try this. However, I am a bit curious why in the simple tutorial: https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-webapp-using-vs?view=aspnetcore-2.2 they don't play with connection strings at all. I actually just followed the tutorial step by step with a brand new app and the only item I do differently is change the DefaultConnection to point to my local instance of sql server rather than the default which is LocalDb. I publish to Azure and still the same error. – Blake Rivell Dec 11 '18 at 18:46
  • I did what you said and took the azure connection string from the publish profile and put it in appsettings.json and redployed. Still getting: The page cannot be displayed because an internal server error has occurred. – Blake Rivell Dec 11 '18 at 18:48
  • After enabling logging I found my error: Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list. I think it has something to do with InProcess in .net core 2.2 – Blake Rivell Dec 11 '18 at 18:53
  • @BlakeRivell looks like an bug https://github.com/aspnet/Templating/issues/837, do you have the latest asp.net core sdk? upgrade VS and try to redo the steps – Marcus Höglund Dec 11 '18 at 18:58
  • @BlakeRivell If you check the .net core 2.2 release, the "Availability in Azure App Service" section https://blogs.msdn.microsoft.com/webdev/2018/12/04/asp-net-core-2-2-available-today/. looks like you could just remove the AspNetCoreHostingModel tag from the web.config. You can do it manually by editing kudos. Type yoursite.scm.azurewebsites.net to get in and then go to the root and edit the web config file – Marcus Höglund Dec 11 '18 at 19:02
0

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.

GarDavis
  • 1,309
  • 3
  • 14
  • 23