【问题标题】:HTTP Error 500.30 Azure.RequestFailedExceptionHTTP 错误 500.30 Azure.RequestFailedException
【发布时间】:2021-06-27 18:17:11
【问题描述】:

我使用 Visual Studio 4.8.04084 将我的应用推送到 Azure 应用服务。我已经为

配置了我的连接
  • Azure 应用配置
  • Azure 密钥库
  • Azure SQL 数据库:我的数据
  • Azure SQL 数据库:身份服务
  • Azure 存储
  • Secrets.json

当我在本地通过 Kestral 服务运行应用程序时,一切正常。但是,当我通过 IIS 运行它时,会遇到以下问题:

Visual Studio 异常消息

Exception thrown: 'Azure.RequestFailedException' in Microsoft.Extensions.Configuration.AzureAppConfiguration.dll
Exception thrown: 'Azure.RequestFailedException' in Navrae.WebApp.dll
An exception of type 'Azure.RequestFailedException' occurred in Navrae.WebApp.dll but was not handled in user code
Service request failed.
Status: 403 (Forbidden)


Headers:
Server: openresty/1.17.8.2
Date: Wed, 31 Mar 2021 15:39:42 GMT
Connection: keep-alive
x-ms-request-id: 09275563-49a0-40e6-88e2-**** (dotting these out just in case)
x-ms-client-request-id: 9adcfd53-1a94-43df-aac8-**** (dotting these out just in case)
x-ms-correlation-request-id: 09275563-49a0-40e6-88e2-**** (dotting these out just in case)
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Authorization, x-ms-client-request-id, x-ms-useragent, x-ms-content-sha256, x-ms-date, host, Accept, Accept-Datetime, Date, If-Match, If-None-Match, Sync-Token, x-ms-return-client-request-id, ETag, Last-Modified, Link, Memento-Datetime, retry-after-ms, x-ms-request-id, x-ms-client-session-id, x-ms-effective-locale, WWW-Authenticate
Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 0

'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Remote Debugger\x64\Runtime\Microsoft.VisualStudio.Debugger.Runtime.NetCoreApp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[22720] iisexpress.exe' has exited with code -1 (0xffffffff).

Azure 应用服务日志

at Azure.Data.AppConfiguration.ConfigurationClient.d__42.MoveNext() at
 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at
 Azure.Core.PageResponseEnumerator.FuncAsyncPageable`1.d__2.MoveNext() at 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.GetResult(Int16 token) at 
Azure.Core.PageResponseEnumerator.FuncAsyncPageable`1.d__2.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at Azure.AsyncPageable`1.d__6.MoveNext() at 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Azure.AsyncPageable`1.d__6.MoveNext() at 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.GetResult(Int16 token) at 
Azure.AsyncPageable`1.d__6.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at 
Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.<>c__DisplayClass20_1.<b__2>d.MoveNext() at
 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.<>c__DisplayClass20_1.<b__2>d.MoveNext() at 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at 
System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() at 
Microsoft.Extensions.Configuration.AzureAppConfiguration.TracingUtils.d__2.MoveNext() at 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at 
System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() at 
Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.d__28.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at 
Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.d__20.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at 
System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() at 
Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.Load() at 
Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers) at 
Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at 
Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration() at
 Microsoft.Extensions.Hosting.HostBuilder.Build() at Navrae.WebApp.Program.d__0.MoveNext() in C:\Users\Work Laptop\source\repos\Navrae\Navrae.WebApp\Program.cs:line 19

Azure 日志链接消息*

{"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}}

当我调试应用程序时,它基本上在 CreateHostBuilder 处失败。我的 ConnectionStrings 都没有填充,我不知道在哪里或如何进一步调试它。

创建HostBuilder

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((context, config) =>
                {
                    var azConfigSettings = config.Build();
                    var azConfigConnection = azConfigSettings.GetConnectionString("REMOVED");
                    if (!string.IsNullOrEmpty(azConfigConnection))
                    {
                        // Use the connection string if it is available.
                        config.AddAzureAppConfiguration(azConfigConnection);
                    }
                    else if (Uri.TryCreate(azConfigSettings["Endpoints:REMOVED"], UriKind.Absolute, out var endpoint))
                    {
                        // Use Azure Active Directory authentication.
                        config.AddAzureAppConfiguration(options =>
                        {
                            options.Connect(endpoint, new DefaultAzureCredential());
                        });
                    }
                    var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("REMOVED")!);
                    config.AddAzureKeyVault(
                    keyVaultEndpoint,
                    new DefaultAzureCredential());
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

【问题讨论】:

    标签: azure visual-studio asp.net-core azure-keyvault


    【解决方案1】:

    您得到的错误是 HTTP 403 Forbidden。

    可能发生的事情是:

    • 当您在本地运行时,您使用的是有权访问 Azure 服务的身份。
    • 在 IIS 中运行时,您使用的网络服务标识无法访问 Azure 服务。

    在 Azure 应用服务中,您可以将其配置为作为“托管标识”运行,然后您可以授予该托管标识访问您正在使用的服务的权限。

    【讨论】:

    • 所以我擦掉了所有东西,我正在实施一些小改动,看看哪里出了问题。我将其设置为具有授予权限的托管身份。我尝试将其关闭但没有解决。我将寻找一些关于如何手动添加所有内容的教程,因为我还是编码新手,而且对 azure 几乎是新手。
    • 您正在使用 5 个服务,这些服务都需要授予托管标识的权限。如果它仍然不起作用,可能你错过了一个。
    猜你喜欢
    • 2020-09-16
    • 2023-02-15
    • 2019-05-17
    • 1970-01-01
    • 2019-08-25
    • 2021-07-16
    • 2020-08-23
    • 2019-06-12
    • 1970-01-01
    相关资源
    最近更新 更多