57
votes

:( Oops. 500 Internal Server Error An error occurred while starting the application.

This message came out when I added database functionality to my asp.net core app and deployed it to iis. When I developed it in Visual Studio, everything went well. But after deploying, this error messages appeared.

I tried to use dotnet myapp.dll to run my app in the deploy folder, and found out it worked well. It is likely that the problem is relation to iis. I tried to add <compilation debug="true">..</compilation> to web.config, but it seems useless. What is problem are actually, or is there any other way to see the detailed error info to help find out what's happened?

11
Did you enable <customErrors> in your web.config?Dai
No, should I enable it ?yitian
Have you installed the ASP.NET Core module on that remote IIS server? If not, you should.Lex Li
I have installed it. The problem is solved. I followed @Set 's answer and found out the log which indicated the sqlserver exception. Thank you all the sameyitian

11 Answers

64
votes
  1. Change stdoutLogEnabled="false" to true and then check the logs at stdoutLogFile=".\logs\stdout". The error(s) there might tell you something.

  2. Check that you set up right Environment Name using ASPNETCORE_ENVIRONMENT environment variable as so use correct settings like connection string. On your machine by default you have "Development" environment.

  3. You may use Error Handling middlewares for showing exceptions like

    app.UseDeveloperExceptionPage();
    
19
votes

Had the same issue. Here is the guide that helped me. Note, that I did not want to install the "Runtime" on the web server, but rather deploy all the necessary files as a stand alone app. Below are the steps in a more abbreviated form:

  1. On your local PC, Determine which version to publish based on your server. I was targeting Windows Server 2008, R2 which meant i needed to publish win7-x64. Open a command prompt in your project directory and run the command below:

    dotnet publish -c release -r win7-x64

    This creates a publish folder containing hundreds of dlls, an .exe, and web.config located here: bin\Release\netcoreapp2.0\publish

  2. On the web server with IIS, go to this landing page. Click the link for your desired version. Find the link for the Runtime and Hosting Bundle. Click to download and run.

  3. Restart IIS by running this from an elevated command prompt:

    net stop was

    net start w3svc

  4. Copy all of the files in your local publish folder to your desired application folder on the IIS server.

  5. On the server, Open IIS, and create a separate AppPool and Application like normal. For the AppPool, under Basic Settings, change the .NET Framework version to No Managed Code. Make sure your Application in IIS points to your desired folder and the proper AppPool.

  6. Test your web application in a browser.

6
votes

In my case, I got this because I hadn't actually installed the latest 'DotNetCore.2.0.0-WindowsHosting.exe' on the windows server I was running it on... so it was working fine on my local machine in debug and error five hundy'ing on the server.

I had other non trivial to fix issues with the upgrade also... I'd advise avoiding it if you can.

5
votes

Mark333's comment below solved my problem.

Quoting for easy reading:

"I'm using the normal publish provided by Visual Studio. And, I just found out using the latest version of Hosting Bundle will fix the issue. +1 on this microsoft.com/net/download/dotnet-core/runtime-2.1.0-rc1"

I had to install for 1.1 since my app is a little older, but Hosting Bundle fixed it. In my case we deploy to a Docker image for our official environment, but when I want to do some testing locally I publish it and let my local IIS serve it up.

2
votes

I had installed DotNetCore.2.0.5-WindowsHosting.exe on a Windows 2008 R2 Standard machine and encountered the same http 500 error. Logging didn't help (blank logs were generated - and Event Viewer logs were the generic ErrorCode = 0x80070002)

I had to do two things to solve my problem:

  1. Give Read rights to the ApplicationPoolIdentity user (EG: IIS APPPOOL\AppPoolIdentityName) to the website directory and the application directory
  2. I had to install IIS ASP Core under Server Manager (this felt weird, but it worked!)
2
votes

I had the same issue.

My problem was that my connection string to db was not set in appsettings.production.json

And the internal server error 500 was to vague error message.

Changing the stdoutLogEnabled = true did nothing to me so i was not seeing any information about the error.

0
votes

I experienced this issue. The problem was due to my local Sql Server instance. Remote connection were not allowed. So I manually restarted the SQL instance and my App restarted working fine.

0
votes

I had similar issue after istalling dotnetcore-windowshosting using chocolatey while doing AWS ec2 instance bootstrapping.

When I checked my IIS modules AspNetCoreModule was missing.

This solved my issue. https://github.com/aspnet/IISIntegration/issues/434

I had to uninstall chocolatey package, restart machine and install it again.

Hope this helps!

0
votes

Make sure the App Pool has permissions to the folder where your app resides.

0
votes

There is an article called "Configuring IIS, ASP.NET, and SQL Server" which I highly recommend. I followed the steps described there and my asp.net core app now communicates with my SQL database (after being published to IIS):

https://www.codeproject.com/Articles/674930/Configuring-IIS-ASP-NET-and-SQL-Server