小编jus*_*ugh的帖子

从 Blazor WASM 中的 AccountClaimsPrincipalFactory 调用 API

我将 Blazor WASM 与 AzureB2C 结合使用来调用 Azure Functions 中托管的 API。我想在成功登录时调用我的 API,以将用户信息添加/更新到数据库中。我一直在遵循这个指南。当尝试将我键入的 httpclient 注入 AccountClaimsPrincipalFactory 时,我遇到了运行时错误:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常呈现组件:ValueFactory 尝试访问此实例的 Value 属性。System.InvalidOperationException: ValueFactory 尝试访问此实例的 Value 属性。

这显示在浏览器中,但应用程序编译并运行得很好。如果我不注入我的代码,代码会很好用PlatformServiceClient,但我需要进行 API 调用来记录用户。涉及以下文件。我调整了一些东西以简化。这似乎是合适的方法,但我还没有看到在声明工厂中进行 api 调用的示例。

CustomAccountFactory.cs

 public class CustomAccountFactory: AccountClaimsPrincipalFactory<CustomUserAccount>
    {
        public IPlatformServiceClient client { get; set; }
        public CustomAccountFactory(NavigationManager navigationManager,
            IPlatformServiceClient platformServiceClient,
            IAccessTokenProviderAccessor accessor) : base(accessor)
        {
            client = platformServiceClient;
        }

        public override async ValueTask<ClaimsPrincipal> CreateUserAsync(
            CustomUserAccount account, RemoteAuthenticationUserOptions options)
        {
            var initialUser = await base.CreateUserAsync(account, options);

            if (initialUser.Identity.IsAuthenticated)
            {
                //call …
Run Code Online (Sandbox Code Playgroud)

c# asp.net blazor blazor-webassembly

6
推荐指数
1
解决办法
1693
查看次数

标签 统计

asp.net ×1

blazor ×1

blazor-webassembly ×1

c# ×1