动态Web API控制器的授权

时间:2017-12-01 18:46:27

标签: aspnetboilerplate asp.net-boilerplate

如何使用AbpAuthorize或AbpAllowAnonymous属性? 这些控制器的默认行为是什么? 在文档中找不到。

2 个答案:

答案 0 :(得分:0)

AbpAuthorize仅用于检查权限。例如:

  [AbpAuthorize("Administration.UserManagement.CreateUser")]
    public void CreateUser(CreateUserInput input)
    {
        //A user can not execute this method if he is not granted for "Administration.UserManagement.CreateUser" permission.
    }

检查他是否拥有Administration.UserManagement.CreateUser权限。在允许用户执行方法之前。

AbpAuthorize,如果不带参数,只需检查用户是否已登录。

[AbpAuthorize]
public void SomeMethod(SomeMethodInput input)
{
    //A user can not execute this method if he did not login.
}

例如,这将检查用户是否在他可以执行该方法之前登录。

请尝试阅读此处了解更多详细信息:

https://aspnetboilerplate.com/Pages/Documents/Authorization#DocCheckPermission

它会比我更好地解释它。

答案 1 :(得分:0)

您可以将这些属性添加到从AbpController派生的Application Services或Controllers中。基本上它使用拦截并检查当前用户是否具有所需的权限。 (因此需要经过身份验证的用户来检查权限)。因此,首先您需要对用户进行身份验证以深入了解这些权限。

相关问题