Note: Not really answering directly your question, but may help depending of your needs (and the code is too long for comments)
Note 2: Not sure if it works on Core, if it doesn't, tell me and I remove the answer
You can know, in a filter, if another filter is used along with:
public class OneFilter : ActionFilterAttribute, IActionFilter
{
void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
{
// Check if the Attribute "AnotherFilter" is used
if (filterContext.ActionDescriptor.IsDefined(typeof(AnotherFilter), true) || filterContext.Controller.GetType().IsDefined(typeof(AnotherFilter), true))
{
// things to do if the filter is used
}
}
}
public class AnotherFilter : ActionFilterAttribute, IActionFilter
{
// filter things
}
AND/OR
You can put some data in the Route data to let know the Action which Filters are used:
void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.RouteData.Values.Add("OneFilterUsed", "true");
base.OnActionExecuting(filterContext);
}
...
public ActionResult Index()
{
if(RouteData.Values["OneFilterUsed"] == "true")
{
}
return View();
}
RewriteContext
from the response rewrite middleware. – Scorper