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