asp.net-roles

ASP.NET MVC Roles and Security

点点圈 提交于 2019-11-28 07:12:33
问题 Assume like this is my SampleController action method public ActionResult AdminView() { return View() } If want this controller method to be called if the logged in user belongs to admin role, otherwise this method call should be blocked and the user should get an some custom unauthorized access error page. In my asp .net mvc web application, when the user logs in, I am storing the user role in a session as a string. And whenever there is a need to validate the user role, I compare the value

Add User to Role ASP.NET Identity

荒凉一梦 提交于 2019-11-28 03:49:35
I know the new Membership includes a "Simple Role Provider." I can't find any help related to creating a user and assigning a role when the user is created. I've added a user which created the tables on the DB correctly. I see the AspNetRoles , AspNetUserRoles , and AspNetUsers tables. I am wanting to assign a role from AspNetRoles to a user in AspNetUsers which the ID of both the role/user are to be stored in AspNetUserRoles. I'm stuck on the programming part of where and how to do this when I create the user. I have a dropdown list to select the role, but using the Entity CF along with the

MVC 5 - Roles - IsUserInRole and Adding user to role

柔情痞子 提交于 2019-11-27 16:50:49
问题 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 to Microsoft.AspNet.Identity. My question now is, with Microsoft.AspNet.Identity how do i do an action similar to Roles.IsUserInRole? And/or create a relation between the Role and the User. By the way, i'm still trying to understand the new

Adding Role dynamically in new VS 2013 Identity UserManager

天大地大妈咪最大 提交于 2019-11-27 14:12:44
问题 I created a new MVC application in the new VS2013 IDE. I added the following to the Login Action on the AccountController as I wanted to create a default user dynamically: var admin = new ApplicationUser() { UserName = "administrator" }; var result = UserManager.Create(admin, "administrator"); This works great, I then wanted to put this default user into a new default role: user = UserManager.FindByName("administrator"); var roleresult = UserManager.AddToRole(user.Id,"admin"); The second line

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

China☆狼群 提交于 2019-11-27 07:00:43
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 assigned as attributes at design time . (Attributes are compiled in with the DLL so I am presently aware of no

Add User to Role ASP.NET Identity

有些话、适合烂在心里 提交于 2019-11-27 00:10:46
问题 I know the new Membership includes a "Simple Role Provider." I can't find any help related to creating a user and assigning a role when the user is created. I've added a user which created the tables on the DB correctly. I see the AspNetRoles , AspNetUserRoles , and AspNetUsers tables. I am wanting to assign a role from AspNetRoles to a user in AspNetUsers which the ID of both the role/user are to be stored in AspNetUserRoles. I'm stuck on the programming part of where and how to do this when