isinrole

Override the User.IsInRole and [Authorize(Roles = “Admin”)] for MVC4 application

旧城冷巷雨未停 提交于 2019-12-18 13:54:12
问题 I have created a custom role provider for my MVC4 application where I have been successfully able to override CreateRole, GetAllRoles and RoleExists methods and link them to my existing database as follows: namespace Project.Providers { public class MyProvider : System.Web.Security.SqlRoleProvider { private MyContext dbcontext = new MyContext(System.Configuration.ConfigurationManager.ConnectionStrings["MyContext"].ConnectionString); private Repository<MyUser> userRepository; private

User.IsInRole(“fake group”) results in “The trust relationship between the primary domain and the trusted domain failed”

落爺英雄遲暮 提交于 2019-12-12 10:34:01
问题 I have an MVC 3 app, using Windows Authentication with Claims using WIF 4.5. Access to the application is controlled (currently) via membership in an AD group: <deny users="?" /> <allow roles="domain\somegroup" /> <deny users="*" /> In addition to the AD groups, we have custom roles that need to be added. (This app is being converted from Forms to Windows authentication) To support these custom roles (until they are managed in AD), we are adding them as ClaimTypes.GroupSid claims to the user,

My.user.IsInRole always returning false

旧巷老猫 提交于 2019-12-02 17:05:33
问题 Currently, I'm working in one migration request, where we need to change the framework from 3.5 to 4.6.2. Here the problem is after changing the framework below method is not showing result as expected. My.User.IsInRole() is always returning false. If My.User.IsInRole(nlRole.InnerText) Then hasRole = True Exit For End If Also, I tested with below code: Imports System.Security.Principal Class PrincipalCheck Shared Function UserInRole(role As String) As Boolean Dim currPrincipal As New

Override the User.IsInRole and [Authorize(Roles = “Admin”)] for MVC4 application

此生再无相见时 提交于 2019-11-30 10:27:56
I have created a custom role provider for my MVC4 application where I have been successfully able to override CreateRole, GetAllRoles and RoleExists methods and link them to my existing database as follows: namespace Project.Providers { public class MyProvider : System.Web.Security.SqlRoleProvider { private MyContext dbcontext = new MyContext(System.Configuration.ConfigurationManager.ConnectionStrings["MyContext"].ConnectionString); private Repository<MyUser> userRepository; private Repository<Role> roleRepository; public MyProvider() { this.userRepository = new Repository<MyUser>(dbcontext);

Usage of User.IsInRole() in a View

这一生的挚爱 提交于 2019-11-27 14:08:34
In my mvc5 project to disable an action link for unauthorized users i did like this @if (User.IsInRole("Admin") | User.IsInRole("Manager")) { @Html.ActionLink("Add New Record", "ProductTypeIndex", "ProductType") } But if there are many roles to check then this @if() gets long. How to avoid this? Do i need custom helpers for this(if so how can i approach it)? Help appreciated.. You could write your own extension method and use it in your code. public static class PrincipalExtensions { public static bool IsInAllRoles(this IPrincipal principal, params string[] roles) { return roles.All(r =>

Usage of User.IsInRole() in a View

时光怂恿深爱的人放手 提交于 2019-11-26 16:37:16
问题 In my mvc5 project to disable an action link for unauthorized users i did like this @if (User.IsInRole("Admin") | User.IsInRole("Manager")) { @Html.ActionLink("Add New Record", "ProductTypeIndex", "ProductType") } But if there are many roles to check then this @if() gets long. How to avoid this? Do i need custom helpers for this(if so how can i approach it)? Help appreciated.. 回答1: You could write your own extension method and use it in your code. public static class PrincipalExtensions {