AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Example throws unhandled error

Open ChuckBevitt opened this issue 6 years ago • 2 comments

I'm using the latest Visual Studio 2019 and .Net Core as of 10/30/2020

Steps to reproduce:

Create new Blazor Web app using template in Visual Studio 2019

Install Microsoft.Extensions.Http Install Microsoft.AspNetCore.Components.WebAssembly.Authentication

Add using Microsoft.AspNetCore.Components.WebAssembly.Authentication; to Program.cs

Replace: builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

With: builder.Services.AddHttpClient("ServerAPI", client => client.BaseAddress = new Uri("https://www.example.com/base")) .AddHttpMessageHandler();

builder.Services.AddScoped(sp => sp.GetRequiredService() .CreateClient("ServerAPI"));

Add new component 'Test' to Pages folder

Added to top of Test: @page "/Test" @using Microsoft.AspNetCore.Components.WebAssembly.Authentication @inject HttpClient Client

Added the new Test component to the NavMenu

Run in IISExpress in Chrome

Choose Test from the menu

Unhandled exception thrown: Unhandled exception rendering component: No service for type 'Microsoft.AspNetCore.Components.WebAssembly.Authentication.BaseAddressAuthorizationMessageHandler' has been registered.

What am I missing?

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

ChuckBevitt avatar Oct 30 '20 21:10 ChuckBevitt

Hello @ChuckBevitt ... Why aren't you following the guidance in the dedicated topic?

https://docs.microsoft.com/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory

guardrex avatar Oct 30 '20 21:10 guardrex

@ChuckBevitt I'm going to close the issue because we don't have anything actionable for documentation at this time. I recommend that you follow the guidance in the dedicated Hosting with AAD topic, then adopt any desired scenarios from the Additional scenarios topic after that.

guardrex avatar Oct 30 '20 23:10 guardrex