0

I use NTLM in ASP.net MVC5. I'm looking for how I can add to loged user role. I have table with (id_user, role_name). where id_user is a User.Identity.Name . So what I must do to add role "Admin" to loged user?

I add to global.asax:

<authentication mode="Windows" />
<authorization>
  <allow roles="Admin,Menager"/>
  <deny users="?" />
</authorization>
Mateusz
  • 83
  • 9

1 Answers1

0

It's been a while since I worked with MVC5, but here's what's been working for me in the new ASP .NET Core MVC. Your solution should be similar to the scenario below.

For a role (e.g. Admins) in the AspNetRoles table, its Id value must appear in the RoleId field of a record in the AspNetUserRoles table, which maps a user's UserId (Guid) value to that role.

The UserId value can be looked up in the AspNetUsers table, the primary user table.

If the user tables have changed a little, the above table/field names may be a little different for MVC5. So, let me know if you need more help, then I can look into of further and pull up an older project in MVC5.

Shahed C - MSFT
  • 2,831
  • 23
  • 26
  • Thank you for response. i think you tell about "Individual User ACC" not about "Windows Authetication", but it's been a while since I worked with C#. I think i haven't "AspNetRoles table" or tell me where i should looking it. In instruction from studies i have something like this: "Project => ASP.NET Configuration and in security tab..." but i dont see it in Visual studio 2015 – Mateusz Apr 02 '16 at 08:25
  • I find like this: http://stackoverflow.com/questions/6043100/asp-net-mvc-and-windows-authentication-with-custom-roles but I don't understand where and what i must past. – Mateusz Apr 02 '16 at 08:39
  • The tables that I mentioned are the user tables in the database. In my new ASP .net core app, I used FB to auto-generate my tables. For an older version, I found another SO response that provides some options to create the Membership tables: http://stackoverflow.com/questions/19521552/asp-net-mvc-5-identity-create-database-admin-interface – Shahed C - MSFT Apr 02 '16 at 12:46