Two questions about MVC, and Identity

后端 未结 2 1390
滥情空心
滥情空心 2021-01-15 21:22

I am very new to identity and MVC, I am trying to create an MVC app as one of my first projects.

I have been able to follow a few tutorials and have successfully add

2条回答
  •  执念已碎
    2021-01-15 21:57

    1) I would make your own UserValidator inherit from microsoft's UserValidator and handle your extra field.

    Updated:

    2) You can make your own extension method to get the extra field you added.

    public static string GetSomething(this IIdentity identity)
    {
        if (identity.IsAuthenticated)
        {
            var userStore = new UserStore(new Context());
            var manager = new UserManager(userStore);
            var currentUser = manager.FindById(identity.GetUserId());
            return something = currentUser.something;                
        }
        return null;
    }
    

提交回复
热议问题