简体   繁体   中英

Elastic Beanstalk not running any commands when deploying asp.net using “Publish to AWS” Visual Studio command

I just registered at AWS services (micro, free) and trying to deploy asp.net mvc 4 application. Everything is working fine, web application deployed and running (the web part, database, etc), but when i am trying to write to filesystem (for example, when i`m saving a file), i'm gettig an exception

System.UnauthorizedAccessException: Access to the path 'C:\\inetpub\\wwwroot.logs\\xxx.log

The folder "C:\\inetpub\\wwwroot\\.logs" exists.

I tried to grant a permission to folder to DefaultAppPool using commands. I have following web project structure:

  • WebHost
    • .ebextensions
      • aws.config

aws.cofig has following content:

container_commands:
  01-logscreate:
    command: "mkdir C:\inetpub\wwwroot\.logs > create-logs.log"
    cwd: "C:/inetpub/wwwroot/.ebextensions"
  01-logspermission:
    command: "icacls \"C:/inetpub/wwwroot/.logs\" /grant DefaultAppPool:(OI)    (CI) > p-logs.log"
    cwd: "C:/inetpub/wwwroot/.ebextensions"

When i accessing the file, i resolving the full path using

HostingEnvironment.MapPath("~/.logs/xxx.log")

But when i trying to write to this file, a get an exception.

Relative path of '.ebextensions' in deployment package is

Content\\D_C.git\\udsmonitoring.app\\WebHost\\obj\\Debug\\Package\\PackageTmp\\.ebextensions

Thanx in advance

The app pool that gets deployed runs with limited permissions. It doesn't have access to write to that directory.

Further, you really shouldn't need to be writing logs to the instance file system itself. These instances are transient. If you need a logging solution, consider using CloudWatch or LogEntries. Both probably fit into your existing code base with only a config file change required. In general, if what you're doing ends up with you needing to remote into the EC2 instance to do or see something, consider taking an alternate approach.

Finally, if you really do have a need to write to that directory from within the context of your app, you can add a command in your ebextensions that uses appcmd to set the app pool identity to one with greater privileges...or have a command that sets the directory permissions explicitly.

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