19
votes

I am trying to publish as ASP.NET Core project with a hosting provider that supports ASP.NET Core. I am getting 500 Internal Server Error which I believe is very common. So I searched through the internet and various forums and then I checked the processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" in web.config and they look to be correctly converted with processPath="dotnet" and arguments=".\MyApplication.dll".

I also checked the connection string and it points to production DB server that's working. I confirmed the DB connection by changing the connection string to production DB and running project local. It works and I get the production DB access.

I also tried to get the error info by using the below in my Startup.cs (irrespective of env):

app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();

I have also enabled stdoutLog in web.config, but I don't see that folder either:

stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout"

I also tried to change applicationUrl and launchUrl in launchSettings.json to my prod Url, but that didn't work as well.

So, the 500 Internal Server Error refuses to go away, and I still don't have a useful error message. The page just says:

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

I would really appreciate if someone could help me here.

8
Who are you using to host your project? Have you tried integrating an exception catching tool, something like Raygun? (even just an evaluation trial) to see if you get something more meaningful?Clint
I am using HostBuddy. I haven't tried anything like that before. I'll need to see how to use if I can.user6542823

8 Answers

29
votes

I have also enabled stdoutLog in web.config as but I don't see that folder either:

stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout"

There is one trick here - you must create both folders logs and stdout manually - then and only then IIS will create log file inside logs folder (not stdout as you could expect) - don't ask me why, because I don't know why ;)


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

Usually, means problems with a configuration in Startup.cs - the most common problems include an issue with DB itself, an issue with migrations (if you are using Code First approach), problems with appsettings.js, problems with Social Logins credentials (like missing SecretKey)...

Please refer to log file in .\logs\stdout - this is the quickest way to find details about the problem :)


app.UseDeveloperExceptionPage();

app.UseDatabaseErrorPage();

Those will work after your WebApp fully started, but not while starting the application.

5
votes

in web.config file change modules="AspNetCoreModuleV2" to modules="AspNetCoreModule"

and watch this video https://www.youtube.com/watch?v=clCR3k6kkD8

4
votes

Thanks to Lukasz for his comments. I was able to see the log and it stated that "ClientId option must be provided". The problem was with the UserSecrets. Since secrets.json is only available in Development, there were no secrets found in Production. Once I had the secrets in my appSettings.json, it worked fine.

Moreover, To replicate this in Local environment, just go to Project properties and change the environment variable ASPNETCORE_ENVIRONMENT to 'Production' and run in local. This will replicate the 500 Internal Server Error in local and you'll get the error message.

3
votes

Also, ensure that the ASP.NET Core Windows Server Hosting bundle is installed. THis creates a reverse proxy between IIS and the Kestral server.

More Info:

https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x#tabpanel_tfsY37MhAQ_aspnetcore2x

3
votes

I would like to add some more info to @Lukasz Makowej answer.

I found out the reason why to have to create the folder, in microsoft documentation it is said that:

stdoutLogFile - Optional string attribute.

".....Any folders provided in the path must exist in order for the module to create the log file...."

So you have to create it yourself :) Check it out here:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.0

I also must said that in my case I had to validate that the web-site had the permissions to access to the "log" folder.

1
votes

Make sure your web.config is good. I've been stomped more than once by a syntactically good web.config that referred to a module (Rewrite) that wasn't on the server. No error messages anywhere, other than the 500 response error.

0
votes

Std log wasn't working for me, I had to uninstall all .ENT Core runtime / SDK versions from the server and my local to install the latest one and it worked after publishing everything again from scratch.

Another thing that helped was binding the IIS app to port 5000 without any dns so it actually showed me errors on http://localhost:5000

0
votes

Encountered this issue yesterday, we also had no logging, no eventlog message whatsoever. Then we checked the site's authentication settings via the IIS-manager to double-check the settings. And pop suddenly a popup with an error message 'Error on line XXXX'. Turned out the configuration section was locked in the website's config at server-level.

So try unlocking the relevant IIS configuration settings at server level, as follows:

  • Open IIS Manager
  • Select the server in the Connections pane
  • Open Configuration Editor in the main pane
  • In the Sections drop down, select the section to unlock, e.g. system.webServer => security => authentication

  • Click Unlock Attribute in the right pane

  • Repeat for any other settings which you need to unlock
  • Restart IIS (optional) - Select the server in the Connections pane, click Restart in the Actions pane