posts - 609,  comments - 13,  views - 64万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
来源:https://blog.csdn.net/lwplvx/article/details/113614095
var endpoint = httpContext.GetEndpoint();
if (endpoint != null)
{
    var permissionAttribute = endpoint.Metadata.GetMetadata<PermissionsAttribute>();
}

这样就可以获取标记在Controller的Action上面的自定义Attribute了:

复制代码
/// <summary>
/// 查询全部角色
/// </summary>
/// <returns></returns>
[HttpPost]
[Permissions("0102_View")]
public JsonResult GetAllSysRoles([FromBody] SysRoleParaDto dto){
    //...
}
复制代码

 自定义Attribute

复制代码
namespace XCGWebApp.Attributes
{
    [System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)]
    public class PermissionsAttribute : System.Attribute
    {
        public PermissionsAttribute()
        {
            PermissionCodes = "";
        }
        public PermissionsAttribute(string permissionCodes)
        {
            PermissionCodes = permissionCodes;
        }
        /// <summary>
        /// 权限编码,英文逗号分隔。
        /// </summary>
        public string PermissionCodes { get; set; } = string.Empty;
    }
}
复制代码

 

posted on   邢帅杰  阅读(164)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示