asp.net-identity-2

ASP.net Identity 2.1 Get all users with roles

℡╲_俬逩灬. 提交于 2019-12-07 04:44:57
问题 How can I get a list of users including the role name per user? My app has the default tables of an MVC Project. I'm able to retrieve all users using Identity 2.1 like this: Model public class GetVendorViewModel { public IList<ApplicationUser> Vendors { get; set; } } Controller public ActionResult Index() { var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); var roleStore = new RoleStore<IdentityRole>(ac); var roleManager = new

Updating Roles when granting Refresh Token in Web Api 2

守給你的承諾、 提交于 2019-12-07 03:07:53
问题 I have developed an authentication mechanism in Asp.Net Web Api 2 with the feature for granting refresh tokens, based on the tutorial on Taiseer's blog. Here is my question. Assume the following scenario: A user logs in using password and get a refresh token and an access token. The access token in fact includes what roles he is in (hence his authorities within the app). In the mean time the system admin will change this person's roles, so once his access token expires and he wants to use the

How to get role name for user in Asp.Net Identity

戏子无情 提交于 2019-12-07 00:40:43
问题 I am trying to figure out how to find user role name in identity framework. I have such configuration that there will be only one role assigned to a user. So, I tried using public string GetUserRole(string EmailID, string Password) { var user = await _userManager.FindAsync(EmailID, Password); var roleid= user.Roles.FirstOrDefault().RoleId; } But what I get is just RoleId and not RoleName. Can anyone help me to find the RoleName for the user? 回答1: In your code, user object represents the

Why is the IdentityUser class in the Microsoft.AspNet.Identity.EntityFramework namespace and not in the Core package?

↘锁芯ラ 提交于 2019-12-06 19:58:10
问题 Why is the IdentityUser class in the Microsoft.AspNet.Identity.EntityFramework package instead of being included in the Microsoft.AspNet.Identity.Core package? Why should it depend on EntityFramework? It seems to be a simple class. What am I missing? I typically separate by Data layer from my DAL. Adding a dependency to EntityFramework for the IdentityUser class seems a bit much. 回答1: The design of the core of Identity is not coupled to EF or to any specific shape of user and role types.

How to use ActiveDirectoryMembershipProvider with ASP.Net Identity?

怎甘沉沦 提交于 2019-12-06 17:04:23
问题 I am trying to learn how to use ASP.Net Identity. My scenario is that I have to authenticate against Active Directory. For that purpose I am trying to use ActiveDirecotoryMembershipProvider . What I have to do is - Authenticate user/password against Active Directory. Check whether user is present in my own database. The way I did it is I configured in my web.config to use ActiveDirectoryMembershipProvider as default membership provider. Then I override PasswordSignInAsync method in my

EF Code First Fluent API - Cascade Delete

那年仲夏 提交于 2019-12-06 15:35:04
I have two models: public class User { ..... public virtual UserProfile UserProfile { get; set;} } public class UserProfile { ..... public virtual User User { get; set;} } The User is the master table and the relation is one to one. One user has only one UserProfile. How can I define the relationship between User and UserProfile using EF CodeFirst Fluent API in such a way that when I delete one user from User table the user profile from Userprofile is also deleted? Use WillCascadeOnDelete modelBuilder.Entity<UserProfile>() .HasKey(c => c.Id) .HasRequired(c => c.User) .WithRequiredDependent(c =

List User and Role in asp.net identity 2.0

会有一股神秘感。 提交于 2019-12-06 15:28:22
问题 How do i display a list of Users and their Roles in ASP.NET Identity 2.0. Example... John Doe - Admin Bob Smith - User So far I have created a UserRoleViewModel public string fname { get; set; } public string rname { get; set; } In the controller, I have done the following... ApplicationDbContext db = new ApplicationDbContext(); UserRoleViewModel obj = new UserRoleViewModel(); var result = from u in db.Users select new UserRoleViewModel { fname = u.FirstName, rname = ??? }; return View(result

Asp.Net Identity and multiple login mechanisms

。_饼干妹妹 提交于 2019-12-06 14:09:45
问题 I'd like to create an application that would be as open as possible to different login mechanisms. So I've used Asp.Net Identity. For (almost) free, this system gives me: Simple accounts OpenID with Facebook, Microsoft, Google and more If you use the other templates, you can also have Organisational Accounts with the following 3 options: Cloud - Single Organisation Cloud - Multiple Organisations On-Premises My use cases are showing that I need a mix of all of that: Users that want a simple

How do I add impersonation in MVC ASP.NET Identity 2.0

廉价感情. 提交于 2019-12-06 12:19:01
问题 I am wondering how I add user impersonation on mvc identity 2.0, I seen some people using this: FormsAuthentication.SignOut(); FormsAuthentication.SetAuthCookie(user.UserName, false); This wont work for me it wont even sign out I use : AuthenticationManager.SignOut() So how do I go along doing this I have admin panel what lists users, I get the userId or userName, what exactly do I have to do? I have never used Claims so I dont understand it much I wont need to revert back to user they can

Authorize and GetRoles doesn't work in ASP.NET Identity

旧时模样 提交于 2019-12-06 11:49:49
问题 I am using ASP.NET Identity 2.1.0 using Entity Framework implementation. Authentication works fine but role based security has problem. Although I've added role to the user but this code returns empty : var roles= UserManager.GetRoles(User.Identity.GetUserId()); Also Authorization based on roles of logged in user fails. when user redirects to a controller like below application redirects him to the login page. [Authorize(Roles = "Admin")] public abstract partial class AdminAreaController :