加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – vNext. AspNet.Identity和自定义UserStore. User

发布时间:2020-12-16 03:16:31 所属栏目:asp.Net 来源:网络整理
导读:我想了解vNext. 我编写了自定义UserStore,它与MongoDB一起使用并实现了这些接口: public class UserStore : IUserStoreApplicationUser,IUserPasswordStoreApplicationUser,IUserSecurityStampStoreApplicationUser,IUserLoginStoreApplicationUser,IUserCl
我想了解vNext.
我编写了自定义UserStore,它与MongoDB一起使用并实现了这些接口:

public class UserStore : IUserStore<ApplicationUser>,IUserPasswordStore<ApplicationUser>,IUserSecurityStampStore<ApplicationUser>,IUserLoginStore<ApplicationUser>,IUserClaimStore<ApplicationUser>,IUserEmailStore<ApplicationUser>,IUserRoleStore<ApplicationUser>,IUserTwoFactorStore<ApplicationUser>

在Startup.cs中添加:

app.UseServices(services =>
        {

            services.AddIdentity<ApplicationUser>()
                .AddUserStore(() => { return new UserStore(); })
                .AddUserManager<UserManager<ApplicationUser>>()
                .AddHttpSignIn();

            services.AddMvc();
        });

然后尝试使用Visual Studio模板中未更改的AccountController并遇到麻烦.
登录时,在UserStore.FindByNameAsync()中获取ObjectDisposedException – 称为UserStore.Dispose().
在github.com/aspnet上的UserManager代码中,Store.Dispose()仅在UserManager.Dispose()中调用.
我可以忽略Dispose的调用,一切正常,但这不是好方法.

所以我不知道该怎么做

附:问题是:什么(以及为什么)可以调用UserStore.Dispose()?

解决方法

在vNext中,DI内置并管理身份服务的生命周期.在处理服务之后,您可能尝试使用身份,默认情况下,身份服务的生命周期范围限定为请求,因此,例如,如果您尝试挂起对用户管理器的引用并在多个请求中重复使用它,那么会导致ObjectDisposedException.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读