Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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
Asp.net mvc 3 AuthenticateRequest和AuthorizeRequest之间有什么区别_Asp.net Mvc 3_Security_Authentication_Authorization - Fatal编程技术网

Asp.net mvc 3 AuthenticateRequest和AuthorizeRequest之间有什么区别

Asp.net mvc 3 AuthenticateRequest和AuthorizeRequest之间有什么区别,asp.net-mvc-3,security,authentication,authorization,Asp.net Mvc 3,Security,Authentication,Authorization,你能解释一下ASP.NET MVC 3中HttpApplication.AuthenticateRequest和HttpApplication.AuthorizeRequest之间的区别吗?什么时候会发生?假设这种情况: 我的用户有一个名为isbanked的属性,我想在每个请求中检查他/她的isbanked属性。如果是true,我会将用户重定向到错误页面。但不是所有的请求,只是请求其操作由[Authorize]属性签名。好的,在这种类型的操作中,是否会发生HttpApplication.Auth

你能解释一下
ASP.NET MVC 3
HttpApplication.AuthenticateRequest
HttpApplication.AuthorizeRequest
之间的区别吗?什么时候会发生?假设这种情况:

我的
用户
有一个名为
isbanked
的属性,我想在每个请求中检查他/她的
isbanked
属性。如果是
true
,我会将
用户
重定向到错误页面。但不是所有的请求,只是请求其操作由
[Authorize]
属性签名。好的,在这种类型的操作中,是否会发生
HttpApplication.AuthenticateRequest
HttpApplication.AuthorizeRequest
或其他任何操作

我知道我可以在
登录
操作中检查此属性。但我的意思是:

  • 用户请求登录
  • 我检查了属性
    isbanked
    ,它是
    false
  • 用户已登录
  • 用户查看网站的某些页面
  • 管理员禁止该用户(当他登录时)
  • 用户请求具有
    [Authorize]
    属性的页面(操作)
  • 用户已登录(在此之前,还记得吗?)
  • 所以我必须显示请求的页面
  • 但是用户给出了管理员禁止的标志
  • 如何阻止用户查看请求的页面

提前谢谢。

我认为您不需要处理
HttpApplication.AuthenticateRequest
HttpApplication.AuthorizeRequest
中的任何一个。我会使用自定义的
Authorize
属性来解决这个问题

public class MyAuthorizeAttribute : AuthorizeAttribute {

        protected override bool AuthorizeCore(HttpContextBase httpContext) {
            bool authorizerPrimarily = base.AuthorizeCore(httpContext);

            if(authorizedPrimarily){
               return user_not_banned;
            }

            return authorizerPrimarily;
        }
}
您可以从
httpContext.user.Identity.name
获取用户名。使用它从数据库中获取数据

更新评论-1

要将被禁止的用户重定向到特定页面,您可以执行以下操作:

if(authorizedPrimarily){
   if(user_banned){
      httpContext.Response.Redirect("url of banned message");
      return false;
   }

  return true;
}

我认为您不需要处理
HttpApplication.AuthenticateRequest
HttpApplication.AuthorizeRequest
。我会使用自定义的
Authorize
属性来解决这个问题

public class MyAuthorizeAttribute : AuthorizeAttribute {

        protected override bool AuthorizeCore(HttpContextBase httpContext) {
            bool authorizerPrimarily = base.AuthorizeCore(httpContext);

            if(authorizedPrimarily){
               return user_not_banned;
            }

            return authorizerPrimarily;
        }
}
您可以从
httpContext.user.Identity.name
获取用户名。使用它从数据库中获取数据

更新评论-1

要将被禁止的用户重定向到特定页面,您可以执行以下操作:

if(authorizedPrimarily){
   if(user_banned){
      httpContext.Response.Redirect("url of banned message");
      return false;
   }

  return true;
}

+1好的,谢谢。好主意。那么,我如何将用户重定向到指定的页面,例如带有消息的页面:您被禁止!如果用户被禁止,使用我指定的过程只会将您重定向到登录页面。我做过类似的事情,比如重定向到其他页面。你可以看到我问。虽然没有人回答。+1好的,谢谢,好主意。那么,我如何将用户重定向到指定的页面,例如带有消息的页面:您被禁止!如果用户被禁止,使用我指定的过程只会将您重定向到登录页面。我做过类似的事情,比如重定向到其他页面。你可以看到我问。虽然没有人回答。