1
votes

I am trying to create an ASP.Net Core 3 webapp that uses Azure B2C for authentication. I created a WebApp using the template in Visual Studio and have configured the appsettings.json with appropriate values.

The app launches fine and when I click the Sign In button, I receive the following error:

Error

However when I dotnet run from Code, I can see the following:

Hosting Env = Development

Hosting environment = Development which I think contradicts the error message. When I click Sign In I can briefly see I am being redirected to AzureB2C which is sending me back.

How can I set Development mode to reveal more about the error here?

Edit: Startup.cs is not changed from the default using the WebApp template with B2C selected as auth.

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
                .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
        services.AddControllersWithViews();
        services.AddRazorPages();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }
        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });
    }
1
Can you show you have configure the middleware in Configure() (in Startup class)?juunas

1 Answers

0
votes

From a testing on a development perspective you can move the app.UseDeveloperExceptionPage(); to outside the if and comment that if else, that way you should be able to see the problem when debugging the app again.

Also, for your error message a commom error is a misconfiguration of user attributes on the user flows, try to add de Azure ID and email there (you should be able to access that following Azure AD B2C > User Flows > Select the flow > Declarations on your tenant portal.