In previous post, I have written article about how to publish Asp.net core on shared hosting. And some of you maybe find 403 error when deploy Asp.net core. Feel free to read previous article about Asp.net core.
In this article tutorial, this is common error that you can find when deploying Asp.net core and I have read it forums like Stackoverflow and others.
Error Message
If you’ve ever seen this message when hitting your ASP.NET Core app:
“An error occurred while starting the application. .NET Framework <version number> | Microsoft.AspNetCore.Hosting version <version number> | Microsoft Windows <version number>”
It looks a little something like this:
Why You See This Error?
It basically means something really bad happened with your app. Some things that might have gone wrong:
- You might not have the correct .NET Core version installed on the server.
- You might be missing DLL’s
- Something went wrong in your Program.cs or Startup.cs before any exception handling kicked in
Although you ask your hosting provider to see it on IIS, you won’t find the answer since the error is not there. This is because Event Logging must be wired up explicitly and you’ll need to use the Microsoft.Extensions.Logging.EventLog package, and depending on the error, you might not have a chance to even catch it to log to the Event Viewer.
How to Fix This Error
Instead of the Event Viewer, if you’re running behind IIS, we can log the request out to a file. To do that:
- Open your web.config
- Change stdoutLogEnabled=true
- Create a logs folder
- Unfortunately, the AspNetCoreModule doesn’t create the folder for you by default
- If you forget to create the logs folder, an error will be logged to the Event Viewer that says: Warning: Could not create stdoutLogFile \\?\YourPath\logs\stdout_timestamp.log, ErrorCode = -2147024893.
- The “stdout” part of the value “.\logs\stdout” actually references the filename not the folder. Which is a bit confusing.
- Unfortunately, the AspNetCoreModule doesn’t create the folder for you by default
- Run your request again, then open the \logs\stdout_*.log file
Note – you will want to turn this off after you’re done troubleshooting, as it is a performance hit.
So your web.config’s aspNetCore element should look something like this
<aspNetCore processPath=”.\YourProjectName.exe” stdoutLogEnabled=”true” stdoutLogFile=”.\logs\stdout” />
Doing this will log all the requests out to this file and when the exception occurs, it will give you the full stack trace of what happened in the \logs\stdout_*.log file
I hope it will fix your issue!