Authorize attribute v Authorizer.Authorize



在我的Orchard模块中,我正在考虑用对Authorizer.Authorize()的调用来替换控制器操作中MVC的AuthorizeAttribute。优点是,如果用户没有被授权访问某个页面,我可以重定向回主页,从而不会告诉他们这是身份验证问题。

使用这个有任何安全问题吗:

public ActionResult Edit( int id ) {
    if ( !_authorizer.Authorize( Permissions.MyPermission ) ) 
        return Redirect("~/");
    // do stuff here and return
}

而不是这个:

[Authorize]
public ActionResult Edit( int id ) {
    // do stuff here and return
}

非常感谢卫生检查。

根据Hazza的反馈,Authorizer.Authorize()版本允许Orchard权限系统的粒度。当内置的ASP.NET角色系统足够时,[Authorize]属性非常有效。

我可能会根据控制器的操作来使用两者的组合。感谢您的投入Hazza!

最新更新