[英]How can I set folder permissions for elastic beanstalk windows application?
I am currently building a C# WebApi 2 application that I will be uploading to an Amazon Elastic Beanstalk instance to deploy.我目前正在构建一个 C# WebApi 2 应用程序,我将上传到 Amazon Elastic Beanstalk 实例进行部署。 I am having success so far, and on my local machine, I just finished testing the file upload capability in order for clients to upload images.到目前为止我已经成功了,在我的本地机器上,我刚刚完成了文件上传功能的测试,以便客户端上传图像。
The way it goes is I accept the multipart/formdata in the Web Api and save the temp file (with a random name like BodyPart_24e246c7-a92a-4a3d-84ef-c1651416e667) to the App_Data folder.它的方式是我接受 Web Api 中的 multipart/formdata 并将临时文件(使用随机名称,如 BodyPart_24e246c7-a92a-4a3d-84ef-c1651416e667)保存到 App_Data 文件夹。 The temporary file is put into an S3 Bucket and I create a reference in my SQL Server database to it.临时文件被放入一个 S3 存储桶中,我在我的 SQL Server 数据库中创建了一个对它的引用。
Testing works fine with single or multiple file uploads locally but when I deploy the application to Elastic Beanstalk and try to upload I get errors like "Could not find a part of the path 'C:\\inetpub\\wwwroot\\sbeAPI_deploy\\App_Data\\BodyPart_8f552d48-ed9b-4ec2-9986-88cbffd673ee'" or a similar one saying access is denied altogether.在本地上传单个或多个文件时,测试工作正常,但是当我将应用程序部署到 Elastic Beanstalk 并尝试上传时,出现类似“找不到路径的一部分 'C:\\inetpub\\wwwroot\\sbeAPI_deploy\\App_Data\\BodyPart_8f552d48- ed9b-4ec2-9986-88cbffd673ee'”或类似的人说访问被完全拒绝。
I have been trying to find the solution online for a few hours now, but the AWS documentation is all over the place and tutorials/other questions seem to be outdated.几个小时以来,我一直试图在网上找到解决方案,但 AWS 文档到处都是,教程/其他问题似乎已经过时。 I believe it has something to do with not having permission to write the temporary files on the EC2 server, but I can't figure out how to fix it.我相信这与没有权限在 EC2 服务器上写入临时文件有关,但我不知道如何修复它。
Thanks very much in advance.首先十分感谢。
This is already possible since April 2013, see also here : Basically the steps you need to perform are the following:自 2013 年 4 月以来,这已经成为可能,另请参见此处:基本上您需要执行的步骤如下:
MyApp
with your project name (not solution name) displayed in Visual Studio将MyApp
替换为 Visual Studio 中显示的项目名称(不是解决方案名称)All set!!搞定!! Be sure there's a file within App_Data otherwise Visual Studio won't publish it.确保App_Data 中有一个文件,否则 Visual Studio 不会发布它。
{ "containercommands": { "01-changeperm": { "command": "icacls \\"C:/inetpub/wwwroot/MyApp_deploy/App_Data\\" /grant DefaultAppPool:(OI)(CI)" } } }
To give write permission to your DefaultAppPool you can要为您的 DefaultAppPool 授予写权限,您可以
create an .ebextensions folder创建一个 .ebextensions 文件夹
create a config file and place it in your .ebextensions folder创建一个配置文件并将其放在您的 .ebextensions 文件夹中
This will change permission to your wwwroot folder这将更改您的 wwwroot 文件夹的权限
container_commands:
01-changeperm :
command : 'icacls "C:\\inetpub\\wwwroot" /grant "IIS APPPOOL\DefaultAppPool:(OI)(CI)F"'
I had the same problem (unable to write to a file in the App_Data
folder of my web application on Elastic Beanstalk).我遇到了同样的问题(无法在 Elastic Beanstalk 上写入我的 Web 应用程序的App_Data
文件夹中的文件)。
In my case it was sufficient to create a dummy file in the App_Data
folder in my Visual Studio project.就我而言,在我的 Visual Studio 项目的App_Data
文件夹中创建一个虚拟文件就足够了。 When I did this, the App_Data
folder was created during deployment with permissions that allow the web application to write to it.当我这样做时, App_Data
文件夹是在部署期间创建的,具有允许 Web 应用程序写入的权限。
No need for .ebextensions
to change folder permissions. .ebextensions
无需更改文件夹权限。
The App_Data folder does not have write permissions by default, and you would have to set appropriate permissions during deployment of your apps. App_Data 文件夹默认没有写入权限,您必须在部署应用程序期间设置适当的权限。
Check out this post for a detailed explanation of how to do it: http://thedeveloperspace.com/granting-write-access-to-asp-net-apps-hosted-on-aws-beanstalk/查看这篇文章以获取有关如何执行此操作的详细说明: http : //thedeveloperspace.com/granting-write-access-to-asp-net-apps-hosted-on-aws-beanstalk/
This question is pretty old but for anyone else who ends up having the same issue.这个问题已经很老了,但对于最终遇到同样问题的其他人来说。 I had the same issue with AWS.我在 AWS 上遇到了同样的问题。 Connect to your instance and change the properties for the folder you want to upload files to.连接到您的实例并更改要将文件上传到的文件夹的属性。 Select the folder you want to grant read/write access to.选择要授予读/写访问权限的文件夹。 Click on properties and set the permissions that way.单击属性并以这种方式设置权限。
My issue was with uploading images to the server.我的问题是将图像上传到服务器。 I couldn't put it in the App_Data folder since that is a special offer reserved for the app only and I needed the images to be accessible through the URL.我不能把它放在 App_Data 文件夹中,因为这是一个专为应用程序保留的特别优惠,我需要可以通过 URL 访问图像。 So I created another folder "Uploads".所以我创建了另一个文件夹“上传”。 Published my api then connected to the instance through remote desktop.发布我的 api,然后通过远程桌面连接到实例。 Located the Content folder, and set the properties to read/write for DefaultAppPool.找到 Content 文件夹,并将 DefaultAppPool 的属性设置为读/写。 That solved my problem, hope this helps someone out there.这解决了我的问题,希望这可以帮助那里的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.