Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC4表单身份验证Active Directory自定义授权属性_C#_Asp.net Mvc 4_Active Directory_Authorization_Forms Authentication - Fatal编程技术网

C# MVC4表单身份验证Active Directory自定义授权属性

C# MVC4表单身份验证Active Directory自定义授权属性,c#,asp.net-mvc-4,active-directory,authorization,forms-authentication,C#,Asp.net Mvc 4,Active Directory,Authorization,Forms Authentication,在我的C#MVC4应用程序中,我使用基于表单的身份验证和Active Directory。我有一个自定义的广告会员提供商。我已经成功地测试了它可以读取和验证用户所属的组。现在,我正在尝试创建一个自定义授权属性,该属性将执行以下操作: if (user is logged-in/not timed-out/authenticated) { if (user's role is equal to role 1 or role 2) { return a specif

在我的C#MVC4应用程序中,我使用基于表单的身份验证和Active Directory。我有一个自定义的广告会员提供商。我已经成功地测试了它可以读取和验证用户所属的组。现在,我正在尝试创建一个自定义授权属性,该属性将执行以下操作:

if (user is logged-in/not timed-out/authenticated)
{
   if (user's role is equal to role 1 or role 2)
      {
        return a specific view or (preferably) perform a specific redirect to action
      }
   else
      {
       return a different specific view or (preferably) perform a different specific     redirect to action
      }
}
else
    {    
     return View
    }
以下是我到目前为止的情况:

public class AuthorizeEditAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext.Request.IsAuthenticated)
            {
                if ((httpContext.User.IsInRole("group1")) || (httpContext.User.IsInRole("group2")))
                {

                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
}

我不知道如何执行重定向任务。我已经看了这篇文章,讨论了如何进行重定向,但不明白如何将其与目前为止的文章结合起来。特别是因为我认为我必须使用AuthorizationCore来获得对httpcontext.user的访问权,这是我执行的第一次检查,我不知道如何传入AuthorizationContext类型的另一个参数,该参数似乎是沿着重定向的所需路径传递的。

我认为您也应该覆盖该方法。这有一个
AuthorizationContext
参数,允许您将结果设置为您喜欢的
RedirectResult

请查看是否有帮助