gpt4 book ai didi

asp.net-mvc - Web API OData Controller 和授权属性

转载 作者:行者123 更新时间:2023-12-01 12:46:36 25 4
gpt4 key购买 nike

我正在尝试使用 MVC 样式的授权过滤器作为 OData Web API Controller 的 Get() 操作方法的属性,但授权过滤器被忽略了。授权属性可以与 EntitySetController 或 ODataController 一起使用吗?

public class MyEntityController : EntitySetController<MyEntity, int>
{
[CustomAuthorizeAttribute(AccessPermission.View)]
[Queryable( AllowedQueryOptions = AllowedQueryOptions.All)]
public override IQueryable<MyEntity> Get()
{
// Contents omitted.
}
}

public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public AccessPermission RequiredPermission { get; set; }

public CustomAuthorizeAttribute(AccessPermission requiredPermission)
{
RequiredPermission = requiredPermission;
}
}

最佳答案

是的,他们可以,但是自定义 Auth Attributes 应该继承自 System.Web.Http.AuthorizeAttribute

试试这个实现:

public class CustomAuthorizeAttribute : System.Web.Http.AuthorizeAttribute
{
public AccessPermission RequiredPermission { get; set; }

public CustomAuthorizeAttribute(AccessPermission requiredPermission)
{
RequiredPermission = requiredPermission;
}
}

关于asp.net-mvc - Web API OData Controller 和授权属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15261836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com