DEV Community

Cover image for How I fixed FileStream error on Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer
Lichy_queen
Lichy_queen

Posted on

How I fixed FileStream error on Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer

Hi everyone! It feels surreal that I am writing my first post on dev.to. I am really excited and looking forward to sharing my experiences as I journey through software engineering and development.
Today, I would be writing about the issues I encountered while deploying an Asp.net Core microservice on IIS and how it was solved.

The microservice in question is meant to create images from a byte array and write these images to a folder.
Note: This application was performing this function perfectly on my development machine. I am sure we can all relate to this...LOL!

However upon deployment, API calls to this service just returned 500 error code, no meaningful message as to the cause of the error, you can imagine how vague this is. All I could see on the log file was "|ERROR|Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer|Connection ID "17437937763084142462", Request ID "8000077f-0001-f200-b63f-84710c7967bb": An unhandled exception was thrown by the application.
|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request finished in 2980.7792ms 500
|INFO|Microsoft.Hosting.Lifetime|Application is shutting down..."
.

After several hours of googling, I was able to solve this error by granting IISUsers read and write access to the microservice folder referenced in IIS. Previously, IISUsers had only read access.
Boom! API calls to the service were successful.
I also gave IISUsers read and write access on "C:\inetpub\wwwroot" folder to forestall this occurrence on any other application hosted on IIS. This created another issue as the Angular web application for the service refused to load and threw this error.
Alt Text
Oops!!! Another bottleneck.
To solve this, I followed the steps below;

  • I opened IIS File Manager
  • Navigated to "Sites"
  • Selected and double-clicked the folder of the Angular web application.
  • Then I selected Authentication, double-clicked to select "Anonymous authentication" Alt Text Alt Text
  • After double-clicking on Anonymous authentication, I clicked on "Edit" under actions and set Anonymous User Identity to Application Pool Identity. Alt Text Alt Text
  • Then restarted IISServer.

Voila! This solved the issue with the web application.
Most times during deployment our applications can have issues because of inadequate permission settings, unfortunately, most times IIS does not explicitly tell you the error as in my case.

So basically while deploying, make sure to give your application appropriate read and write access to avoid bugs like this.

Happy Coding guys!!!

Top comments (0)