简体   繁体   中英

How can I set permissions to a specific folder with Elastic Beanstalk using a C# ASP.NET Core app?

I'm new to ASP.NET Core and I'm building an app. One of the functionality that works locally is uploading a file and saving it to a wwwroot/uploads folder that I've created.

I have no issues saving this file and later accessing or downloading this file locally. Once I began deploying my application using Elastic Beanstalk, I repeatedly get the following error once I try to upload the file:

"UnauthorizedAccessException: Access to the path 'C:\.netpub\AspNetCoreWebApps\AppName\wwwroot\uploads\filename.txt' is denied."

Googling this issue led me to add a.ebextensions folder to house config files to add write permissions and to add this folder to my source bundle. My understanding was to set it up as follows:

source bundle zip:
-deployment manifest 
-source code folder:
 -all dlls
 -wwwroot folder
 -.ebextensions folder added here

At this point, I tried to create a JSON config file but I still got the same error. I tried to create a YAML config file but I still got the same error.

YAML file:

container_commands:
    01-changeperm:
        command: icacls "C:/inetpub/AspNetCoreWebApps/AppName/wwwroot" /grant DefaultAppPool:(OI)(CI)F /T

JSON file:

{
    "container_commands": {
        "01": {
            "command": "icacls "C:/inetpub/AspNetCoreWebApps/AppName/wwwroot" /grant DefaultAppPool:(OI)(CI)F /T"
        }
    }
}

If anyone is curious on the stack when it breaks:

UnauthorizedAccessException: Access to the path 'C:\.netpub\AspNetCoreWebApps\AppName\wwwroot\uploads\filename.txt' is denied.

System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)

System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)

System.IO.FileStream..ctor(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)

AppName.Utilities.FileHelper.WriteFileToFolder(IFormFile formFile, string filePath) in FileHelper.cs AppName.Controllers.HomeController.Create(FileUpload model) in HomeController.cs

-

How can I tell if my config files are even being run? I'm not seeing them run as events on EBS which is the only place I know to look for them.

Alternatively, are the config files themselves set up wrong?

Finally, does anyone have advice for what else could be the issue here? I'm new to ASP.NET Core and EBS so all feedback is appreciated.

Container commands are run from the staging directory, where your source code is extracted prior to being deployed to the application server. Any changes you make to your source code in the staging directory with a container command will be included when the source is deployed to its final location.

When these config commands are run, the only folder present is C:/.netpub/AspNetCoreWebApps, that is why your command does not work, detailed information is here

The correct command will be

{
  "container_commands": {
    "01": {
      "command": "icacls \"C:/inetpub/AspNetCoreWebApps\" /grant DefaultAppPool:(OI)(CI)F"
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM