MVC4和EF5在SQL Active Directory验证和角色 [英] MVC4 and EF5 with Active Directory Authentication And Roles in SQL

查看:130
本文介绍了MVC4和EF5在SQL Active Directory验证和角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现MVC4一个项目,并与EF5 Active Directory验证但不是具有角色的广告组,我必须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 entities to support...I hope it could help.


      
  • 角色

  •   
  • 用户

  •   
  • 的UserRole

  •   

我试图用[作用]注释。这可能吗?

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

我有点失落,我需要帮助,请!!!!

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

推荐答案

我想我明白了。

请随时改进和重新发布它:

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;

    }

}

这篇关于MVC4和EF5在SQL Active Directory验证和角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆