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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:22:27+00:00 2026-05-26T02:22:27+00:00

I have an ActionFilter that is applied to my base controller which checks certain

  • 0

I have an ActionFilter that is applied to my base controller which checks certain things in the request and session and makes sure that you are allowed to view the requested URI.

This has worked fine until now when we need to disallow all pages (as it exists today) but allow a few URIs here and there.

Ideally, I would apply an attribute to the ones that we want to allow and then check for that attribute in the filter and allow if it exists, but I cannot figure out how to make that happen in the filter.

Any ideas or suggestions?

  • 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-26T02:22:27+00:00Added an answer on May 26, 2026 at 2:22 am

    I spent over an hour trying to figure this out then I posted here on SO. Minutes later, it hit me.

    First, I created an attribute

    public class AlwaysAllowAnonymousAttribute : Attribute {}
    

    Second I marked my action or controller with the above attribute

    Finally, in my ActionFilter i did this

    public class VerifyResourceAccess : ActionFilterAttribute, IActionFilter
    {
        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
    
            var actionAttributes = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AlwaysAllowAnonymousAttribute), false);
            var controllerAttributes = filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(AlwaysAllowAnonymousAttribute), false);
            bool alwaysAllow = (actionAttributes.Length > 0) || (controllerAttributes.Length > 0);
    
            if (!alwaysAllow) {
                /* ... Some logic for checking if this user is allowed to access this resource  ... */
            }
    
            base.OnActionExecuting(filterContext);
        }
    }
    

    Any action or controller that is marked with the attribute will always have access allowed to it.

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

Sidebar

Related Questions

I have an ActionFilter that checks if a parameter in the URL is valid.
I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
I have a custom login-actionfilter where that I'm trying to upgrade to mvc 2
I have an NHibernate action filter that sets up and disposes of the session/transaction
I have a controller method that looks like this: [AcceptGet] public ActionResult Index(SecurityMatrixIndexViewModel model)
I have a .NET MVC application which makes extensive use of AJAX and modal
I have written an action filter which detects a new session and attempts to
Currently I have an ActionFilter that gets the current users name from HttpContext and
I have an external-to-my-solution web service that I'm using in an ActionFilter. The action
I have an ASP.net MVC controller called Designs that has an action with the

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.