小编Jor*_*ion的帖子

如何在asp.net中的动作过滤器中添加参数?

我有以下过滤器属性,我可以像这样将字符串数组传递给属性[MyAttribute("string1", "string2")].

public class MyAttribute : TypeFilterAttribute
{
    private readonly string[] _ids;

    public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl))
    {
        _ids = ids;
    }

    private class MyAttributeImpl : IActionFilter
    {
        private readonly ILogger _logger;

        public MyAttributeImpl(ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<MyAttribute>();
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            // HOW DO I ACCESS THE IDs VARIABLE HERE ???
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如何将字符串数组传递_ids给动作过滤器的实现?我错过了一些非常明显的东西!?

c# custom-action-filter actionfilterattribute asp.net-core-mvc asp.net-core

16
推荐指数
1
解决办法
9075
查看次数