gpt4 book ai didi

c# - 如何扩展 Microsoft.AspNet.Identity.IUser

转载 作者:行者123 更新时间:2023-11-30 17:41:34 25 4
gpt4 key购买 nike

我正在尝试为我的 Web 应用程序实现一个带有电子邮件确认的注册过程。我正在使用 IdentityServer3.AspNetIdentity 服务。

public class AspNetIdentityUserService<TUser, TKey> : UserServiceBase
where TUser : class, Microsoft.AspNet.Identity.IUser<TKey>, new()
where TKey : IEquatable<TKey>
{

我的问题是 TUser 需要 Microsoft.AspNet.Identity.IUser 接口(interface)。在我实现的功能中,传入的用户上下文是正确的,但我无法访问您在以下两张图片中看到的所有属性。

enter image description here

enter image description here

http://img5.fotos-hochladen.net/uploads/b6aa42c662dd1kv063h4g5p.png http://img5.fotos-hochladen.net/uploads/d75b1e6462dd1wi9clqj6e7.png

您知道如何扩展 Microsoft.AspNet.Identity.IUser 以达到我有权访问属性 Lastname 和 Firstname 的效果吗?

最佳答案

这里的TUserIdentityServer3中自定义实现的类,它继承自IdentityUser,用于用户身份。

您无法访问这些属性,因为 TUser 是 IdentityServer3.Host.WebHost.AspId.User 的对象,由基类 IdentityUserIUser< 表示.

Quickwatch 会显示对象属性,但它不会出现在智能感知中。

您需要将 TUser 转换为 IdentityServer3.Host.WebHost.AspId.User

var user = new TUser() as IdentityServer3.Host.WebHost.AspId.User;
user.FirstName = "Tester";
user.LastName = "Doer";

这应该为您提供解决方法。

关于c# - 如何扩展 Microsoft.AspNet.Identity.IUser<TKey>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32783995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com