asp.net-roles

ASP.NET MVC3 Role and Permission Management -> With Runtime Permission Assignment

安稳与你 提交于 2019-12-17 08:53:12
问题 ASP.NET MVC allows users the ability to assign permissions to functionality (i.e. Actions) at Design Time like so. [Authorize(Roles = "Administrator,ContentEditor")] public ActionResult Foo() { return View(); } To actually check the permission, one might use the following statement in a (Razor) view: @if (User.IsInRole("ContentEditor")) { <div>This will be visible only to users in the ContentEditor role.</div> } The problem with this approach is that all permissions must be set up and

Asp.net WebForms Enable Roles

﹥>﹥吖頭↗ 提交于 2019-12-11 19:49:13
问题 I've created a Webpage via Visual Studio 2017 using ASP.NET WebForms. I'm using the build-in User Management and created some users. Now I want to use the Role-Function. First I've enabled the roleManager, but then I get a new error "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion" I've tried to use the aspnet_regsql.exe to add the necessary parts to the database, but now I have two kind of tables in my database: AspNetUsers and aspnet_Users. What Do I have to do, to enable

Adding users to roles on registring failed ASP.NET MVC3

谁都会走 提交于 2019-12-08 12:43:27
问题 I like to enable users to choose their role on register in asp.net mvc web application. I have previous add roles via asp.net addministration tool. Here is the code I am using in register methods public ActionResult Register() { ViewData["roleName"] = new SelectList(Roles.GetAllRoles(), "roleName"); return View(); } [HttpPost] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser

Extending the RoleProvider GetRolesForUser()

爱⌒轻易说出口 提交于 2019-12-08 08:34:55
问题 The GetRolesForUser() method in the RoleProvider takes the user login name and returns the list of roles for that user. But in my application this is not enough, I need a few more pieces of information to be able to get the user's roles. How can I get this extra information into the method? I have it in the Session , but I found out that Session is not available in the RoleProvider . What I had in mind was putting this extra info in some class that extends MembershipUser , assuming I can get

Custom roles in ASP.NET

五迷三道 提交于 2019-12-07 23:00:08
问题 I am working on an ASP.NET website which uses forms authentication with a custom authentication mechanism (which sets e.Authenticated programmatically on protected void Login_Authenticate(object sender, AuthenticateEventArgs e) ). I have an ASP.NET sitemap. Some elements must be displayed only to logged in users. Others must be displayed only to one, unique user (ie. administrator, identified by a user name which will never change). What I want to avoid: Set a custom role provider: too much

Extending the RoleProvider GetRolesForUser()

北城以北 提交于 2019-12-06 15:52:45
The GetRolesForUser() method in the RoleProvider takes the user login name and returns the list of roles for that user. But in my application this is not enough, I need a few more pieces of information to be able to get the user's roles. How can I get this extra information into the method? I have it in the Session , but I found out that Session is not available in the RoleProvider . What I had in mind was putting this extra info in some class that extends MembershipUser , assuming I can get to it inside the RoleProvider . But I don't know how to create the CustomMembershipUser and make it

Inheritance of Authorized Roles in controller classes

给你一囗甜甜゛ 提交于 2019-12-06 06:46:55
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 abstract class ControllerAuthorities:Controller { } [Authorize(Roles = "Admin")] public abstract class AdminController:ControllerAuthorities { } [Authorize(Roles = "Employee")] public abstract class EmployeeController:AdminController { } [Authorize(Roles = "Sales")] public abstract class SalesController:EmployeeController { } First question, will

Trying to get all roles in Identity

北战南征 提交于 2019-12-05 02:02:28
I am trying to get a list of all the roles in my application. I have looked at the following post Getting All Users... and other sources. Here is my code which I think is what I am supposed to do. var roleStore = new RoleStore<IdentityRole>(context) var roleMngr = new RoleManager<IdentityRole>(roleStore); List<string> roles = roleMngr.Roles.ToList(); However, I’m getting the following error: Cannot implicitly convert type GenericList(IdentityRole) to List(string) . Any suggestions? I am trying to get the list so I can populate a dropdown list on a registration page to assign a user to a

Attribute inheriting from AuthorizeAttribute not working

三世轮回 提交于 2019-12-04 10:35:03
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 read on the question so far, I created an attribute that inherits AuthorizeAttribute which looks like this (MyAppRole is an enum, btw) : [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public sealed class AuthorizeRoleOrSuperiorAttribute : AuthorizeAttribute { private MyAppRole

ASP.NET Identity, add another user to role instantly (they don't have to log out and in again)

不羁的心 提交于 2019-12-03 09:32:46
问题 First of all, I'm aware of this question: MVC 5 AddToRole requires logout before it works? and this one: What is ASP.NET Identity's IUserSecurityStampStore<TUser> interface? so please don't mark this as a duplicate. I'm trying to add another user to a role (i.e. the user we're adding to the role is not the current user. If they are, the answer to first question I linked to is sufficient.) Like so: IdentityResult result = await userManager.AddToRoleAsync(userID, roleName); The two situations I