1

I have my base controller and action filter in the same namespace but in different classes. I created a class inside of the base controller which requests http headers, and I would like to call that method inside of my action filter.

If I do a simple Details dtls = GetHeaders() the intelliSense asks if I want to create another method GetHeaders() inside of the action filter.

So my question is can I call the GetHeaders() method inside of the BaseController class directly from the action filter? How would I do so? If not, how could I call that method?

namespace Infrastructure
{
    public class BaseController
    {
        public Details GetHeaders()
        {
            //Get the headers
        }
    }

    public class MyFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            //Call GetHeaders() to get Header1 data
        }
    }
}

2 Answers 2

7

Have you tried getting the controller from the filterContext

var controller = filterContext.Controller as BaseController;

controller.GetHeaders();
Sign up to request clarification or add additional context in comments.

Comments

0
public class MyFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        base.OnActionExecuting(filterContext);

        filterContext.HttpContext.Response.Redirect("~/BaseController/GetHeaders");
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.