ASP.NET role management helps you to manage authorization, allowing you to specify which resources various users in your application are allowed to access. Role management lets you group users by assigning them to roles.
Questions tagged [asp.net-roles]
226 questions
6
votes
2 answers
Programmatically log a user in to asp.net membership and roles?
I'm working on an Asp.Net 4.0 web application which is using the Membership and Roles features of Asp.Net.
In the application, there will be three roles which have access to the login page and one role which doesn't.
The way it is supposed to work…

inksmithy
- 536
- 1
- 5
- 16
5
votes
1 answer
Razor pages assign roles to users
I am wondering how to create and assign roles in Razor Pages 2.1. application.
I have found how to make them for MVC application (How to create roles in asp.net core and assign them to users and…

Bogdan
- 864
- 10
- 18
5
votes
1 answer
Attribute inheriting from AuthorizeAttribute not working
I'm currently trying to implement security in a new ASP MVC 5 application, based on user roles. The goal is to prevent users from accessing certain controllers or controller methods if they don't have a certain role (or higher). Based on what I've…

ZipionLive
- 722
- 1
- 12
- 23
5
votes
1 answer
How do I check to see if an Identity role exists before it is created?
In my application I am creating Identity Roles but want to make sure that one of the same name does not exist. Here is what I have tried
public ActionResult Create()
{
var Role = new IdentityRole();
return View(Role);
}
[HttpPost]
public…

Skullomania
- 2,225
- 2
- 29
- 65
5
votes
5 answers
Get all users within a role. ASP.NET Identity
I can get all users like this
var users = UserManager.Users.ToList();
I can find a role like this
var role = db.Roles.SingleOrDefault(m => m.Name == "User");
I want to list all users with the role name "User" in the AspNetRoles table (I have User…

Anders
- 375
- 2
- 5
- 18
5
votes
2 answers
MVC 5 - Roles - IsUserInRole and Adding user to role
In MVC4 i used Roles.IsUserInRole to check if a given user is in some role. However, with MVC5 i can't do it anymore...
At first, it asked me to enable RoleManager at the web.config but then i discovered that microsoft moved away from Web.Security…

Leandro Soares
- 2,902
- 2
- 27
- 39
5
votes
0 answers
Roles.GetRolesForUser() returns empty array
I'm using Roles.GetRolesForUser() and when I call it I get {string[0]}. However, when I type in a users name as a hard coded string like this: Roles.GetRolesForUser("theloggedinusersname"), I get {string[2]} [0]: "AccountingAdmin" [1]: "Admin". …

Aaron Salazar
- 4,467
- 10
- 39
- 54
4
votes
1 answer
Modifying .NET Core Roles depending on which organization the user is requesting access to (per-request)
I have a use case where a user of our .NET Core API can belong to multiple "organizations" and have different roles within those orgs.
For example, if they POST to a Location/Create endpoint on behalf of OrganizationId = 1, they should have Admin…

Adam Schofield
- 43
- 3
4
votes
0 answers
How to Associate a User Role to a Custom Entity with ASP.NET Core Identity
In my ASP.NET Core Application I have created two Roles:
CompanyAdministrator
CompanyViewer
Company is an entity on my database.
Any user can create a Company and be an CompanyAdministrator of it.
However, if one user provides access to another…

Luis Sérgio
- 629
- 6
- 8
4
votes
1 answer
Custom Authorize Attribute (follow-up)
Ok following up with this thread, here's what I came up with...
public class SharweAuthorizeAttribute : AuthorizeAttribute
{
private bool isAuthenticated = false;
private bool isAuthorized = false;
public new string[] Roles { get; set;…

Kassem
- 8,116
- 17
- 75
- 116
4
votes
2 answers
Inheritance of Authorized Roles in controller classes
I've created controller classes to assist with Role authorization.
I have a base class ControllersAuthorities, which is the highest level of authority. I have created the other classes to extend each base class.
[Authorize(Roles = "Owner")]
public…
user3956566
4
votes
1 answer
Error message does not appear on failed login using asp.net mvc 4 with a custom role provider?
I'm trying to implement a custom role provider and I found a tutorial and followed it.
Here is the link: http://techbrij.com/custom-roleprovider-authorization-asp-net-mvc
When I try to login using a user account that does not exist, the error…

Randel Ramirez
- 3,671
- 20
- 49
- 63
4
votes
1 answer
Does FluentSecurity replaces Asp.Net membership provider or it's supposed to complement/work together with it?
I'm working on an Asp.Net MVC4 site and I wanted to create a membership provided backed by Redis. Since I need the user privileges to be dynamic - user can create new roles in the admin dashboard - I was considering on using FluentSecurity…

Adabada
- 303
- 3
- 15
3
votes
1 answer
EF DbContext per web request + Custom RoleProvider = RoleProvider per web request or singleton?
Using EF DbContext wrapped in interface(s), dependency injected per web request, to make sure the entire request deals with the same context. Also have a custom RoleProvider which consumes the DbContext by interface to customize authorization…

danludwig
- 46,965
- 25
- 159
- 237
3
votes
3 answers
ASP.NET Membership/Roles - how to link user to multiple applications/roles?
I am working on a project to break-up a large web site into smaller, more specific sites. I need to be able to restrict access to these sites to only users that have the necessary permissions, and would like to make use of the existing…

Marcus Guinane
- 139
- 5
- 12