Reputation: 579
System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at Microsoft.Identity.Web.AuthorityHelpers.BuildAuthority(MicrosoftIdentityOptions options)
at Microsoft.Identity.Web.WebApiAuthenticationBuilderExtensions.<>c__DisplayClass1_0.b__0(JwtBearerOptions options)
at Microsoft.Extensions.Options.ConfigureNamedOptions1.Configure(String name, TOptions options)
at Microsoft.Extensions.Options.OptionsFactory
1.Create(String name)
at Microsoft.Extensions.Options.OptionsMonitor1.<>c__DisplayClass11_0.<Get>b__0()
at System.Lazy
1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy
1.CreateValue()
at System.Lazy1.get_Value()
at Microsoft.Extensions.Options.OptionsCache
1.GetOrAdd(String name, Func1 createOptions)
at Microsoft.Extensions.Options.OptionsMonitor
1.Get(String name)
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme)
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Upvotes: 3
Views: 8290
Reputation: 11881
In my case the reason was the missing "https://" in the configs of the appsettings.json file. Just adding it to the instance worked.
Contents of 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"
},
...
}
Upvotes: 5
Reputation: 874
Error usually happens when a string without http:// or https:// is provided as an argument to new Uri(string)
. To avoid throwing an exception you can use,
new Uri(urlString, UriKind.RelativeOrAbsolute);
Upvotes: 0