小编Enr*_*que的帖子

如何在 blazor 页面上使用 usermanager?

你好社区我有一个问题如何usermanagerblazor页面 WebAssembly 中使用?通过注入:

@inject UserManager<ApplicationUser> UserManager;
Run Code Online (Sandbox Code Playgroud)

我收到指示,表明缺少使用指令,因为 ApplicationUser 类位于服务器上,并且客户端无权访问服务器。

这是我在 blazor 页面中的代码:

@page "/index"
@inject AuthenticationStateProvider AuthenticationStateProvider
@using Microsoft.AspNetCore.Identity;
@inject UserManager<ApplicationUser> UserManager;

<button @onclick="@LogUsername">Write user info to console</button>
<br />
<br />
@Message

@code {
    string Message = "";

    private async Task LogUsername()
    {
        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
        var user = authState.User;

        if (user.Identity.IsAuthenticated)
        {
            var currentUser = await UserManager.GetUserAsync(user);
            Message = ($"{user.Identity.Name} is authenticated.{ currentUser.Nombre }");
        }
        else
        {
            Message = ("The user is …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api usermanager blazor blazor-webassembly

4
推荐指数
1
解决办法
7285
查看次数