Подтвердить что ты не робот

WebAPI HttpActionExecutedContext получает имя контроллера

Мне нужно получить контроллер, который запускает атрибут фильтра.

У меня есть следующий фильтр:

public override void OnException(HttpActionExecutedContext filterContext) {
    if (filterContext == null) {
        throw new ArgumentNullException("filterContext");
    }


    if (filterContext.Exception != null) {

        // string controllerName = (string) filterContext.....??

        // string actionName = (string) filterContext.....?

        HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.InternalServerError) {
            Content = new StringContent("An unhandled exception was thrown by Customer Web API controller."),
                ReasonPhrase = "An unhandled exception was thrown by Customer Web API controller."
        };

        filterContext.Response = msg;


    }

}

В традиционном MVC это было легко сделать:

string controllerName = (string) filterContext.RouteData.Values["controller"];
string actionName = (string) filterContext.RouteData.Values["action"];

Любая подсказка? Цените его

4b9b3361

Ответ 1

Наконец, я нашел его:

filterContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerName
filterContext.ActionContext.ActionDescriptor.ActionName

Спасибо