【发布时间】:2016-08-27 12:55:52
【问题描述】:
我有以下过滤器属性,我可以像[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)
{
}
}
}
如何将字符串数组_ids 传递给动作过滤器的实现?我是否遗漏了一些非常明显的东西!?
【问题讨论】:
-
因为“TypeFilterAttribute” - 你在使用 ASP.NET Core 吗?
-
是的,我是 - 这会导致问题吗?
-
我在旧的 ASP.NET 中看到了实现我需要的示例,但在核心中,我似乎看不到任何实现 TypeFilterAttribute 类并传递参数的示例。
-
将 asp.net-core 添加到标签...
标签: c# asp.net-core asp.net-core-mvc actionfilterattribute custom-action-filter