Skip to content Skip to sidebar Skip to footer

Mvc4 And Ef5 With Active Directory Authentication And Roles In Sql

I need to implement a project in MVC4 and EF5 with Active Directory Authentication but instead of having AD Groups for Roles, I must implement Roles in SQL. So far I got some entit

Solution 1:

I Think I Got it.

Please feel free to improve and repost it:

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
publicclassARQAuthorize : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        boolallowToUse=false;
        IPrincipaluser= httpContext.User;
        if (!user.Identity.IsAuthenticated)
        {
            returnfalse;
        }
        else{
        try
        {
           Arq.Core.DAL.ArqContextc=newArqContext();
           if (c.Users.Where(u => u.UserName.ToUpper() == user.Identity.Name.ToUpper()).FirstOrDefault().role.RoleDescription == "ADMINS")
           {
               allowToUse = true;
           }
        }
        catch (Exception)
        {

            allowToUse = false;
        }
        }          
            return allowToUse;

    }

}

Post a Comment for "Mvc4 And Ef5 With Active Directory Authentication And Roles In Sql"