ASP.NET Core hosting - 500 internal server error
Asked Answered
C

8

23

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.

Calculation answered 7/1, 2017 at 21:44 Comment(2)
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?Carothers
I am using HostBuddy. I haven't tried anything like that before. I'll need to see how to use if I can.Calculation
D
34

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.

Diverticulitis answered 7/1, 2017 at 22:4 Comment(11)
Thanks Lukasz. I created the folders and now I can see one file generated in logs folder. It is named as 'stdout_sometimestamp.log'. Now, I cannot see this file in editor at hosting website. So, I downloaded that file and tried to open with notepad but it's blank. Even the downloaded size is 0 kb. But in the directory it shows the size as 5 kb. So, once again I am not able to see the error :(Calculation
This is the file but looks like you have insufficient permission level... Perhaps problem is with downloading over HTTP, maybe try access the file via FTP ?Diverticulitis
This file is locked by IIS while Website is running - it's not an issue when I'm accessing a file directly on server/disk, but in your case, it could be a problem - try to stop the IIS and see if then you will have access to the file via hosting website?Diverticulitis
Or try restart - IIS will create new file after every restart, so you should have access to previous logs.Diverticulitis
I tried FTP and got the file. I can see the log now. Thank you so much.Calculation
No problem. BTW what was the reason of '500' in your case?Diverticulitis
It said that ClientId must be provided and that was the message for Facebook login. Now, facebook options use AppId, so I am trying to figure out where did it go wrong and why ClientId message although It works on local.Calculation
Hehe. I had the same problem. I' using UserSecret Tool so my ids/keys are in a different location (outside project/version control), and I've forgotten put them into the server.Diverticulitis
Let us continue this discussion in chat.Calculation
I am still stuck. I get the log as below. How do I use Client Id, Client Secret on server (shared hosting)? : Application startup exception System.ArgumentException: The 'ClientId' option must be provided. at Microsoft.AspNetCore.Authentication.OAuth.OAuthMiddleware1..ctor(RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, UrlEncoder encoder, IOptions1 sharedOptions, IOptions1 options)`Calculation
Just a detail: you don't have to create a folder "stdout" (but you need to create the "logs" folder)Maag
R
9

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

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

Robedechambre answered 22/7, 2019 at 6:27 Comment(0)
C
6

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.

Calculation answered 8/1, 2017 at 7:48 Comment(0)
B
3

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://learn.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x#tabpanel_tfsY37MhAQ_aspnetcore2x

Barnaby answered 26/9, 2017 at 14:23 Comment(0)
K
3

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://learn.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.

Kattegat answered 17/5, 2018 at 9:8 Comment(0)
R
1

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.

Retorsion answered 8/2, 2019 at 21:42 Comment(0)
U
0

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

Uropod answered 7/12, 2018 at 15:36 Comment(0)
N
0

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
Nonconductor answered 5/11, 2019 at 8:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.