系统。UriFormatException:无效URI:无法确定URI的格式。在系统中。Uri。CreateThis(字符串uri、布尔dontEscape、UriKind UriKind(在系统中。Uri。。ctor(字符串uriString(在微软。身份网状物AuthorityHelpers。BuildAuthority(MicrosoftIdentityOptions选项(在微软。身份网状物WebApiAuthenticationBuilderExtensions<>c__DisplayClass1_0.b_0(JwtBearerOptions选项(在微软。扩展。选项。ConfigureNamedOptions1.Configure(String name, TOptions options)
at Microsoft.Extensions.Options.OptionsFactory
1.创建(字符串名称(在微软。扩展。选项。选项监视器1.<>c__DisplayClass11_0.<Get>b__0()
at System.Lazy
1.ViaFactory(LazyThreadSafetyMode模式(在系统中。懒惰的1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy
1.CreateValue((在系统中。Lazy1.get_Value()
at Microsoft.Extensions.Options.OptionsCache
1.GetOrAdd(字符串名称,Func1 createOptions)
at Microsoft.Extensions.Options.OptionsMonitor
1.Get(字符串名称(在微软。AspNetCore。身份验证。AuthenticationHandler `1.InitializeAsync(AuthenticationScheme方案,HttpContext上下文(在微软。AspNetCore。身份验证。AuthenticationHandlerProvider。GetHandlerAsync(HttpContext上下文,字符串身份验证方案(在微软。AspNetCore。身份验证。AuthenticationService。AuthenticateAsync(HttpContext上下文,字符串方案(在微软。AspNetCore。身份验证。身份验证中间件。Invoke(HttpContext上下文(在微软。AspNetCore。诊断。DeveloperExceptionPageMiddleware。调用(HttpContext上下文(
在我的案例中,原因是缺少"https://";在appsettings.json文件的configs中。只需将其添加到实例中即可。
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"
},
...
}
当不带http://或https://的字符串作为参数提供给new Uri(string)
时,通常会发生错误。为了避免抛出您可以使用的异常,
new Uri(urlString, UriKind.RelativeOrAbsolute);