你好社区我有一个问题如何usermanager在blazor页面 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) 我有2个项目。其中一种使用ASP.Net身份验证,另一种使用Windows身份验证,即管理方。我希望Admin项目能够管理其他用户。除了密码,我可以修改所有内容。
如果我使用UserManager.PasswordHasher创建新哈希并更新AspNetUser,则无法使用新密码登录(可以看到已发生更新)。我试图将Asp.Net用户合并到管理项目中,但它与Windows身份验证混乱。
这是一个咸问题吗?有没有一种方法可以进行简单的模型更新,从而在不重新实现整个身份模型的情况下正确更新密码哈希?
我需要使用一些更复杂的规则来验证新的(或更新的)用户的电子邮件地址.
我想过使用进入用户管理器的用户存储,但是IdentityResult在何处以及如何构建?
我只是抛出一个例外,就是这样吗?或者是否有一些额外的验证机制?
当用户与生成的令牌一起注册时,我试图发送确认电子邮件。令牌没问题。但是在发送电子邮件时,我收到此错误:
System.NotSupportedException: Store does not implement IUserEmailStore<TUser>.
Run Code Online (Sandbox Code Playgroud)
我在 Register 方法中 AccountController 中的代码如下所示: 导致错误的是 SendEmailAsync() 方法:
if (result.Succeeded)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
ViewBag.Link = callbackUrl;
return View("DisplayEmail");
}
Run Code Online (Sandbox Code Playgroud)
在我的 IdentityConfig.cs 文件中,我有一个类:
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 ASP.NET Core 2.2,我需要在我的应用程序中生成自定义令牌。
Asp.Net Core Identity UserManager 可以生成经典令牌,例如 EmailVerification,...
但它还有一种生成具有不同用途的令牌的方法(MSFT Docs):
public virtual System.Threading.Tasks.Task<string> GenerateUserTokenAsync (TUser user, string tokenProvider, string purpose);
Run Code Online (Sandbox Code Playgroud)
我需要生成包含以下信息的令牌:
在GenerateUserTokenAsync上我可以添加用户和目的......
但我不知道如何添加(3)和(4),例如ProjectId和RoleId。
我怎样才能稍后检索它以便我可以实际执行该操作。
我该怎么做?
usermanager asp.net-core asp.net-core-identity asp.net-core-2.2