.NET Core 6 Web Application Azure B2C Error - OpenIdConnectAuthenticationHandler message.State is null or empty

Viewed 51

I have Azure AD B2C authentication setup in my .Net Core 6 MVC application, which is working for the most part in my localhost and development server.

However when I have a trailing slash in my Dev website URL (sample URL below) it is showing an error message. So after removing the trailing slash everything works just fine.

  • https://developmenturl.test.net/TEST --> This always works

  • https://developmenturl.test.net/TEST/ --> This always breaks!

Please note above, my dev URL has a path (TEST) after the hostname.

Interesting thing is, when I put a trailing slash and do a fiddler trace it is not even going to the on.microsoft... URL. But the URL without slash always takes me to on.microsoft (Azure B2C).

When the trailing slash is there in the URL, Seems like application just breaks in the app.start() & shows the error below.

Error. An error occurred while processing your request. Request ID: 00-dfsdfskddkdkkdkdhjuuede-kkdlfssdfkskdlfds-00

Details OpenIdConnectAuthenticationHandler: message.State is null or empty.

My appsettings.json

"AzureAdB2C": {
"CallbackPath": "/",
"Instance": "https://<company name>.b2clogin.com",
"ClientId": "*******",
"Domain": "<companyname>.onmicrosoft.com",
"ClientSecret": "*******",
"SignedOutCallbackPath": "/signout/b2c_<company specific>_susi",
"SignUpSignInPolicyId": "b2c_<company specific>_susi",
"ResetPasswordPolicyId": "b2c_1_<company specific>_pwss",
}

My Startup.cs ConfigureServices() method (Tried with and without OpenIdConnectOptions. Behaves the same):

////=================AzureB2C ============//
        services.AddMicrosoftIdentityWebAppAuthentication(Configuration, Constants.AzureAdB2C)
                 .EnableTokenAcquisitionToCallDownstreamApi(new string[] { })
                 .AddInMemoryTokenCaches();
   
        services.AddRazorPages();

        services.AddOptions();
       
        //services.Configure<OpenIdConnectOptions>(Configuration.GetSection("AzureAdB2C"));

        services.AddControllersWithViews()
            .AddMicrosoftIdentityUI();
//--------------------------------------------------------------------
//----////============END AzureB2C ============//-----------------------------------------------------
0 Answers
Related