【问题标题】:Getting error as soon as app starts "UriFormatException: Invalid URI: The format of the URI could not be determined" using .Net core 3.1使用 .Net core 3.1 应用程序启动时出现错误“UriFormatException:无效的 URI:无法确定 URI 的格式”
【发布时间】:2020-08-18 10:05:39
【问题描述】:

System.UriFormatException:无效的 URI:无法确定 URI 的格式。 在 System.Uri.CreateThis(字符串 uri,布尔值 dontEscape,UriKind uriKind) 在 System.Uri..ctor(字符串 uriString) 在 Microsoft.Identity.Web.AuthorityHelpers.BuildAuthority(MicrosoftIdentityOptions 选项) 在 Microsoft.Identity.Web.WebApiAuthenticationBuilderExtensions.c__DisplayClass1_0.b__0(JwtBearerOptions 选项) 在 Microsoft.Extensions.Options.ConfigureNamedOptions1.Configure(String name, TOptions options) at Microsoft.Extensions.Options.OptionsFactory1.Create(字符串名称) 在 Microsoft.Extensions.Options.OptionsMonitor1.<>c__DisplayClass11_0.<Get>b__0() at System.Lazy1.ViaFactory(LazyThreadSafetyMode 模式) 在 System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue() 在 System.Lazy1.get_Value() at Microsoft.Extensions.Options.OptionsCache1.GetOrAdd(字符串名称,Func1 createOptions) at Microsoft.Extensions.Options.OptionsMonitor1.Get(字符串名称) 在 Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme 方案,HttpContext 上下文) 在 Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext 上下文,字符串 authenticationScheme) 在 Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext 上下文,字符串方案) 在 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 上下文) 在 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext 上下文)

【问题讨论】:

  • 请提供更多细节。我希望您尝试在 startup.cs 中配置 jwtOptions,这就是引发此异常的地方。请在其中发布 src 代码。如果我的回答直接适用于您的错误,您会发现它很有帮助。

标签: .net asp.net-core .net-core visual-studio-2019


【解决方案1】:

当一个不带 http:// 或 https:// 的字符串作为参数提供给 new Uri(string) 时,通常会发生错误。为了避免抛出异常,您可以使用,

 new Uri(urlString, UriKind.RelativeOrAbsolute);

【讨论】:

    【解决方案2】:

    在我的情况下,原因是 appsettings.json 文件的配置中缺少“https://”。 只需将其添加到实例即可。

    appsettings.json 的内容:

    {
      "AzureAdB2C": {
        //"Instance": "blah.b2clogin.com", // <- Missing "https://"
        "Instance": "https://blah.b2clogin.com", // <- Fixed version
        "ClientId": "f6fc311c-cf68-4264-9da6-a3aae9727821",
        "Domain": "blah.onmicrosoft.com",
        "SignUpSignInPolicyId": "B2C_1_signupsignin"
      },
      ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2013-12-15
      • 1970-01-01
      相关资源
      最近更新 更多