Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:10:32+00:00 2026-06-10T10:10:32+00:00

I have implemented my own custom Authorization Attribute in MVC 4 by inheriting from

  • 0

I have implemented my own custom Authorization Attribute in MVC 4 by inheriting from AuthorizeAttribute class. I also have a custom ActionFilterAttribute. These both work fine however the problem lies in ordering them. I need the custom Action Filter to run before the custom Authorize Filter.

I have tried using the Order property for the attributes but as i understand it, Authorize Filters will always run before Action Filters.

Does anyone know how to force the Action Filter to execute before the Authorize Filter??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:10:33+00:00Added an answer on June 10, 2026 at 10:10 am

    When you take a look at the source code (available at http://aspnetwebstack.codeplex.com/) you see that this is not possible with the standard Filter classes. IAuthorizationFilter implementations are always executed before IActionFilter implementations. That’s because action filters will not run when authorization filters return a result.

    To solve this you can create your own ControllerActionInvoker descendant class and override the InvokeAction method:

    public class MyControllerActionInvoker : ControllerActionInvoker
    {
        public override bool InvokeAction(ControllerContext controllerContext, string actionName)
        {
            // Your initialization code here
            try
            {
                return base.InvokeAction(controllerContext, actionName);
            }
            finally
            {
                // Your finalization code here
            }
        }
    }
    

    You need to inject your custom MyControllerActionInvoker class into your controllers in a custom ControllerFactory class:

    public class MyControllerFactory : DefaultControllerFactory
    {
        private readonly MyControllerActionInvoker actionInvoker = new MyControllerActionInvoker();
    
        /// <summary>
        /// Retrieves the controller instance for the specified request context and controller type.
        /// </summary>
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            var controllerInstance = base.GetControllerInstance(requestContext, controllerType);
    
            if (controllerInstance != null)
            {
                var typedController = controllerInstance as Controller;
                if (typedController != null)
                {
                    typedController.ActionInvoker = this.actionInvoker;
                }
            }
    
            return controllerInstance;
        }
    }
    

    And of course you now have to register your own MyControllerFactory with the MVC framework. You should do this where you’re also registering your routes:

    var controllerFactory = new MyControllerFactory();
    ControllerBuilder.Current.SetControllerFactory(controllerFactory);
    

    This implementation works fine here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented my own custom Logger for my django site: class SpecialLogger(logging.Logger): def
I have a custom exception class which contains some additional fields. I want these
I need your help. I have write my own custom NSOperation class called GetNewsOperation.
I have implemented a custom TraceListener which both logs the messages sent to method
I have own control implemented in CommonControls assembly (the same namespace). It us 'Custom
So I have implemented my own custom membership provider, currently only overwriting ValidateUser(). I
I have implemented my own simple version of a navigation window, mainly because navigation
Symfony2 and FOS User Bundle issue... I have implemented my own login form in
I have an own Tree object implemented in PHP. Say we have a tree
So, I'd like to implement my own custom authorization system in MVC2. If I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.