ChatGPT解决这个技术问题 Extra ChatGPT

asp.net core app deployed on iis meets 500 internal server error

:( 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?

Did you enable <customErrors> in your web.config?
No, should I enable it ?
Have you installed the ASP.NET Core module on that remote IIS server? If not, you should.
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 same

S
Set

Change stdoutLogEnabled="false" to true and then check the logs at stdoutLogFile=".\logs\stdout". The error(s) there might tell you something. 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. You may use Error Handling middlewares for showing exceptions like app.UseDeveloperExceptionPage();


Thank you very much. I found out the log and the cause is sqlserver exception. I got to the apppool and set it localsystem and everything is ok! BTW, I updated asp.net core tools in visual studio and redeployed and found error messages shown in error page instead of only 500 server. How awful !
B
Beakie

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:

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 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. Restart IIS by running this from an elevated command prompt: net stop was net start w3svc Copy all of the files in your local publish folder to your desired application folder on the IIS server. 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. Test your web application in a browser.


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 :)
D
David van Dugteren

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.


M
Matthew Allen

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.


R
Rots

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:

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


Only needed to do step 1 from a basic pubish to file in VS2017 on Core 2.2
D
Dongolo Jeno

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.


stdoutlog not working for me as well. did you figured out any other solution
D
DOUMBIA Mamadou

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.


p
prashant

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!


t
tno2007

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


M
Mr. TA

In my case, I created a .NET 5 single file output, and I was getting:

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

The problem turned out to be that the EXE file was for some strange reason recognized as a virus by the protection software (CrowdStrike Falcon). Re-building without "single file output" option solved that problem.


u
user2275545

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


g
gartenkralle

It also happens when you install dotnet-hosting-bundle/dotnet runtime beofore IIS.

In this case re-install dotnet-hosting-bundle/dotnet runtime.