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 6021213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:40:49+00:00 2026-05-23T03:40:49+00:00

Currently I have [Authorize] attributes on all of the methods on my AdminController except

  • 0

Currently I have [Authorize] attributes on all of the methods on my AdminController except for the Logon action.

What’s the cleanest way to invert this, so I don’t have to remember to add the attributes to all methods, but rather add an attribute only to the method(s) that should be available without being logged in?

Would I be better just moving the Logon action to its own controller, and applying the [Authorize] attribute to the AdminController class?

  • 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-05-23T03:40:50+00:00Added an answer on May 23, 2026 at 3:40 am

    In ASP.NET MVC 3 you could implement a custom global action filter provider:

    public class MyProvider : IFilterProvider
    {
        public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            var rd = controllerContext.RouteData;
            var controller = rd.GetRequiredString("controller");
            if (string.Equals("admin", controller, StringComparison.OrdinalIgnoreCase) &&
                string.Equals("logon", actionDescriptor.ActionName))
            {
                return Enumerable.Empty<Filter>();
            }
    
            return new[]
            {
                new Filter(new AuthorizeAttribute(), FilterScope.Action, 0)
            };
        }
    }
    

    which could be registered in Application_Start:

    FilterProviders.Providers.Add(new MyProvider());
    

    Now if you are using some DI container such as NInject for example it supports filter binding syntax meaning that you could configure the kernel to inject the filter dynamically based on the context.

    The pros of this approach is that now nomatter what controller or action is being added to your application => it will require authorization.

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

Sidebar

Related Questions

We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
I have this code to de-authorize my FB application for currently logged in user:
Currently, I'm trying to identify which Controller classes in my assembly have the [Authorize]
I have an MVC 2 application that every page requires authorization on (except currently
I current have the following attribute decorating one of the action method. [Authorize(Roles =
I currently have this huge and slow code that takes forever to run.... Im
I have currently processed a credit card using Authorize.net with Card Present settings. The
I'd like to have additional attributes for my User model and don't want to
I currently have an MS Access application that connects to a PostgreSQL database via
I currently have speakers set up both in my office and in my living

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.