成功地实现定制的UserManager<&IUSER GT;在标识2.0 [英] Successfully implementing custom UserManager<IUser> in Identity 2.0

查看:229
本文介绍了成功地实现定制的UserManager<&IUSER GT;在标识2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想浏览黑洞是一种身份的成员的自定义实现。我的目标,现在仅仅是为了得到这条线我的 ApiController 来正确地找回我的UserManager:

I'm trying to navigate the black hole that is the custom implementation of Identity Membership. My goal right now is simply to get this line from my ApiController to correctly retrieve my UserManager:

public IHttpActionResult Index()
{
    var manager = HttpContext.Current.GetOwinContext().GetUserManager<UserManager<MyUser,int>>();
    //manager is null
}

下面是我的设置。在我的启动的配置我成立的WebAPI,并添加我的OwinContext:

Here's my setup. In my Startup's Configuration I set up the WebApi and add my OwinContext:

app.CreatePerOwinContext<UserManager<MyUser,int>>(Create);



我的创建方式:

My Create method:

public static UserManager<User,int> Create(IdentityFactoryOptions<UserManager<MyUser,int>> options, IOwinContext context)
{
   return new UserManager<MyUser,int>(new UserStore(new DbContext()));
}



剩下的就是最基本的实现我可以做。

the rest is the most basic implementation I can make.

MYUSER:

public class MyUser : IUser<int>
{
    public int Id { get; set; }
    public string UserName { get; set; }
}



MyUserStore:

MyUserStore:

 public class MyUserStore : IUserStore<MyUser,int>
 {
    private IdentityDbContext context;
    public MyUserStore(IdentityDbContext c)
    {
       context = c;
    }

    //Create,Delete, etc implementations
 }

MyDbContext:

MyDbContext:

 public class MyDbContext : IdentityDbContext
 {
     public MyDbContext() : base("Conn")
     {

     }
 }

这是所有学习如何识别工作,这一点我敢确信没有人真正知道的缘故。我希望能够完全定制我的用户和角色最终,避免微软的IdentityUser。

This is all for the sake of learning how Identity works, which I'm pretty convinced no one actually knows. I want to be able to fully customize my Users and Roles eventually, avoiding Microsoft's IdentityUser.

再次我的问题,现在是在我的控制器,我正在努力找回我的UserManager当

Again, my issue right now is that in my controller, I am getting null when trying to retrieve my UserManager.

任何及所有帮助是极大的赞赏。

Any and all help is greatly appreciated.

推荐答案

我有几个错误,但主要的一个是,我的启动类看起来像:

I had several errors, but the main one was that my Startup class looked like :

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseWebApi(new WebApiConfig());

        app.CreatePerOwinContext(MyDbContext.Create);
        app.CreatePerOwinContext<MyUserManager>(MyUserManager.Create);
    }
}



当然,OWIN管道将插入我的依赖性< STRONG>在发射出的WebAPI调用。开关周围的人是我的主要问题。

Of course, the OWIN pipeline will plug my dependencies after firing off the WebAPI calls. Switching those around was my main problem.

另外,我终于找到的这个伟大的指南我在谷歌搜索一路下滑。它回答几乎一切,我是在得到。我需要实现一个具体的类,它是一个的UserManager< MYUSER,INT>

In addition, I finally found this great guide way down in my Google search. It answers pretty much everything I was getting at. I needed to implement a concrete class that was a UserManager<MyUser,int>

我希望这能帮助别人以后。

I hope this is able to help someone later on.

这篇关于成功地实现定制的UserManager&LT;&IUSER GT;在标识2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆