I'm trying to download a file. (It was working before) but jsut now it started failing.
This is a .net core 2 web project supported by a web api net core 2 project. It is throwing the following error message.
Error. An error occurred while processing your request. Request ID: 0HLDPTBLNENOG:0000000A
Development Mode Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
First, I don't know how to enable the development mode, I even tried changing the environment variable with this command
setx ASPNETCORE_ENVIRONMENT "development"
but didn't work.
Anyway I tried first logging the process. I have one method in the webapi that locates de file in a repository and returns the file location to the web controller. According to my log it didn't throws an exception and everything went as planned.
In the web controller, everything works smooth until this point
return File(new FileStream(location, FileMode.Open), "application/x-msdownload", filename.doc);
where it is throwing the following exception (this is the line 94 referred in the exception message).
:System.UnauthorizedAccessException: Access to the path 'I:\Repository\Filename.doc' is denied.
at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at AbAWeb.Controllers.DocumentController.Download(String docId) in C:\SOME FOLDERS\Controllers\DocumentController.cs:line 94
So I assume it has something to do with permissions.
I added IUSR, IIS_IUSRS, NETWORK SERVICE, and I even tried with Everyone, and it is still throwing the same exception.
Some posts say I have to add IIS Apppool users, but I couldn't find them in the check names dialog.
The files are located in hard disk I: the web sites are in C:.
Thank you
According with https://learn.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities, you should run the following in a cmd:
ICACLS <Folder Name> /grant "IIS AppPool\DefaultAppPool:F" /t