C# Amazon Linux 2上的.NET 5.0 ASP.NET Web服务器启动错误:“0”;System.UnauthorizedAccessException:访问路径'/root/.dotnet';被拒绝。”;

C# Amazon Linux 2上的.NET 5.0 ASP.NET Web服务器启动错误:“0”;System.UnauthorizedAccessException:访问路径'/root/.dotnet';被拒绝。”;,c#,.net-core,amazon-ec2,.net-5,amazon-linux-2,C#,.net Core,Amazon Ec2,.net 5,Amazon Linux 2,我目前正在尝试在Amazon Linux 2 EC2实例上运行.NET 5.0 ASP.NET应用程序 这是由nginx托管的,在部署时自动与supervisord一起运行。这是我在部署后第一次运行此程序,并从该应用程序的supervisor stderr中找到此错误堆栈跟踪 System.UnauthorizedAccessException: Access to the path '/root/.dotnet' is denied. ---> System.IO.IOExceptio

我目前正在尝试在Amazon Linux 2 EC2实例上运行.NET 5.0 ASP.NET应用程序

这是由nginx托管的,在部署时自动与supervisord一起运行。这是我在部署后第一次运行此程序,并从该应用程序的supervisor stderr中找到此错误堆栈跟踪

System.UnauthorizedAccessException: Access to the path '/root/.dotnet' is denied.
 ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at System.IO.FileSystem.CreateDirectory(String fullPath)
   at System.IO.Directory.CreateDirectory(String path)
   at Microsoft.Extensions.EnvironmentAbstractions.DirectoryWrapper.CreateDirectory(String path)
   at Microsoft.DotNet.Configurer.FileSystemExtensions.<>c__DisplayClass0_0.<CreateIfNotExists>b__0()
   at Microsoft.DotNet.Cli.Utils.FileAccessRetrier.RetryOnIOException(Action action)
   at Microsoft.DotNet.Configurer.FileSystemExtensions.CreateIfNotExists(IFileSystem fileSystem, String filePath)
   at Microsoft.DotNet.Configurer.FileSentinel.Create()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean isDotnetBeingInvokedFromNativeInstaller, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider, Dictionary`2 performanceMeasurements)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)
System.UnauthorizedAccessException:对路径“/root/.dotnet”的访问被拒绝。
--->System.IO.IOException:权限被拒绝
---内部异常堆栈跟踪的结束---
位于System.IO.FileSystem.CreateDirectory(字符串完整路径)
位于System.IO.Directory.CreateDirectory(字符串路径)
位于Microsoft.Extensions.EnvironmentAbstractions.DirectoryWrapper.CreateDirectory(字符串路径)
在Microsoft.DotNet.Configurer.FileSystemExtensions.c_uuDisplayClass0_0.b_u0()中
位于Microsoft.DotNet.Cli.Utils.FileAccessRetrier.RetryOnException(操作)
在Microsoft.DotNet.Configurer.FileSystemExtensions.CreateIfNotExists(IFileSystem文件系统,字符串文件路径)中
在Microsoft.DotNet.Configurer.FileSentinel.Create()上
在Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()中
在Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse上(IFirsTTimeUseNoticesEntel FirstTimeUseNoticesEntel、IASPnetCertificateEntel AspnetCertificateEntel、IFileSentinel toolPathSentinel、Boolean IsDotNetbeing从NativeInstaller调用、DotnetFirstRunConfiguration DotnetFirstRunConfiguration、IEnvironmentProvider Environment Provider、Dictionary'2性能度量)
在Microsoft.DotNet.Cli.Program.ProcessArgs(字符串[]args,TimeSpan startupTime,ITelemetry遥测客户端)
位于Microsoft.DotNet.Cli.Program.Main(字符串[]args)
我很好奇,为什么这是针对根目录创建目录,并给予权限根解决方案,这或它是其他东西?从我的搜索,这似乎没有发生在任何人。我只是非常谨慎,公然给予开放权限的根文件夹,如果这是解决方案在这里


作为参考,以下是我设置此设置的教程:

我也遇到了此问题,因为DOTNET\u CLI\u HOME未定义为supervisor环境变量的一部分,因此当它运行时,会在不需要的地方查找

尝试将其添加到主管服务文件(或附加到任何现有变量):

然后确保重新加载并更新配置:

sudo supervisorctl reread
sudo supervisorctl update
然后你会发现一切都很顺利

sudo supervisorctl reread
sudo supervisorctl update