使用Kudu构建服务部署asp.net core应用程序时遇到UnauthorizedAccessException错误

5

我已经使用Kudu构建服务(直接通过GitHub连接)设置了我的aspnet core 2.2应用程序的持续部署。直到前天都很好,但自从昨天开始尝试部署任何内容时就开始出现UnauthorizedAccessException错误。虽然我的应用程序没有改变。你有什么想法吗?

以下是详细的异常信息:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at Internal.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
   at Internal.Win32.RegistryKey.SetValue(String name, String value)
   at System.Environment.SetEnvironmentVariableFromRegistry(String variable, String value, Boolean fromMachine)
Failed exitCode=1, command=dotnet restore "D:\home\site\repository\myproject.sln"
   at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
An error has occurred during web site deployment.
   at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
   at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.\r\n   at Internal.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)\r\n   at Internal.Win32.RegistryKey.SetValue(String name, String value)\r\n   at System.Environment.SetEnvironmentVariableFromRegistry(String variable, String value, Boolean fromMachine)\r\n   at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)\r\n   at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)\r\n   at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()\r\n   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()\r\n   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)\r\n   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)\r\n   at Microsoft.DotNet.Cli.Program.Main(String[] args)\r\nD:\Program Files (x86)\SiteExtensions\Kudu\86.20224.4450\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

由于您没有进行任何更改,所以我的建议是确保代码正常,您可以先尝试断开Github,然后设置Github进行持续部署。 - Jason Pan
1个回答

9
在kudu中尝试执行“dotnet restore --help”时,我发现连接错误与在kudu中执行“dotnet restore”有关,而不是与我的应用程序有关。查看与错误消息相关的代码https://github.com/dotnet/sdk/blob/5d747e7b4f1450a00eff5844bd76b73588531b2c/src/Cli/dotnet/Program.cs#L152后,我意识到可以通过添加名为DOTNET_ADD_GLOBAL_TOOLS_TO_PATH且值为false的新应用程序设置来解决此问题。 应用程序设置 之后,我就可以像以前一样使用kudu部署我的应用程序。

哇,通过这些更改,它按预期工作了。谢谢!! - Janak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接