我正在尝试编写一些中间件,并且需要了解当前的操作方法(如果有)是否具有特定的过滤器属性,因此我可以根据其存在来更改行为。
因此,在实现IList<IFilterMetadata>
时,是否有可能像在ResourceExecutingContext
上那样获得IResourceFilter
类型的过滤器集合?
最佳答案
今天真的不可能。
在ASP.NET Core 3.0中可能
app.UseRouting();
app.Use(async (context, next) =>
{
Endpoint endpoint = context.GetEndpoint();
YourFilterAttribute filter = endpoint.Metadata.GetMetadata<YourFilterAttribute>();
if (filter != null)
{
}
await next();
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
关于c# - 如何从HttpContext获取ASP.NET Core MVC筛选器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46059401/