I am facing an issue where I am running .NET core app running on IIS and I need to read/write files locally on the machine but I am getting a runtime error when I try to access these files.
Access to the path 'C:\mydata\somedata' is denied.
to avoid this issue I gave permissions to IIS_IUSRS user to read and write on the specified folder on the machine by connecting remotely to the machine and do that and everything is working okay right now.
The problem is that machine is running on aws beanstalk environment so every time that machine restarts a new instance is created without any permissions to IIS_IUSRS user and I need to go again and do it manually
my question, Is there anything I can do to not go through all that hassle of connecting to machine remotely and giving permissions manually?
I made a workaround in my Startup file by adding the following to app middlewares
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath, @"mydata/somedata")),
RequestPath = @"/SomeExampleRequestPath",
EnableDirectoryBrowsing = false
});
It allows you to read write files located locally on the machine without needing to give IIS read-write permissions