0

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 entities to support...I hope it could help.

  • Role
  • User
  • UserRole

I'm trying to use [Role] annotation. Is it possible?

I'm a little lost, I need a Help PLEASE!!!!

0

1 Answer 1

0

I Think I Got it.

Please feel free to improve and repost it:

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

            allowToUse = false;
        }
        }          
            return allowToUse;

    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.