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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:17:36+00:00 2026-05-19T10:17:36+00:00

I am using a custom Membership Provider. Everything is working great. However, in my

  • 0

I am using a custom Membership Provider. Everything is working great. However, in my web.config file I have “deny users” enabled so the entire site is locked down.

This works great. The user is redirected to the login page.

Now, I have a few controllers/actions that I want to allow anonymous access. About page, password reset, etc.

The only way I can figure out how to do this is to UNLOCK the entire site, put [Authorize] attributes on every controller and remove them for the controller/actions I want anonymous.

This seems backwards to me. I prefer to lock everything down by default and unlock what is anonymous.

Is there a way around this?

Thanks!

  • 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-19T10:17:37+00:00Added an answer on May 19, 2026 at 10:17 am

    I can think of alternative ways to implement this, but they all involve using a customized AuthorizeAttribute. One way to do this would be to have a base controller using said customized AuthorizeAttribute that all of your controllers derive from. This attribute would be customized to prevent anonymous (and unauthorized) access to an action unless it’s controller or the action itself has been decorated with another attribute — say the AnonymousEnabledAttribute. All of your controllers would derive from this controller and thus inherit it’s standard “no anonymous by default” behavior. You would then simply decorate the controllers/actions you want to be anonymous with the AnonymousEnabledAttribute — providing the override for that controller or action. Or, for a controller, simply don’t inherit from the protected controller and all of it’s actions become public.

    Oh, and your whole site would have to remain open.

    [OverridableAuthorize]
    public abstract class ProtectedController : Controller
    {
    }
    
    public class MostlyProtectedController : ProtectedController
    {
        public ActionResult ProtectedAction()
        {
        }
    
        [AnonymousEnabled]
        public ActionResult PublicAction()
        {
        }
    }
    
    [AnonymousEnabled]
    public class ExplicitlyPublicController : ProtectedController
    {
        // inherits additional behaviors, but anonymous is enabled by attribute
    }
    
    public class PublicByOmissionController : Controller
    {
        // doesn't inherit and is thus public -- assuming whole site is open
    }
    
    public class AnonymousEnabledAttribute : Attribute
    {
    }
    
    public class OverridableAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization( AuthorizationContext context )
        {
              context.HttpContext.Items["ActionDescriptor"] = context.ActionDescriptor;
              base.OnAuthorize( context );
        }
    
        public override bool AuthorizeCore( HttpContextBase context )
        {
             var actionDescriptor = context.Items["ActionDescriptor"] as ActionDescriptor;
             if (actionDescriptor == null)
             {
                 throw InvalidOperationException( "ActionDescriptor missing from context" );
             }
             var attribute = actionDescriptor
                                 .GetCustomAttributes( typeof(AnonymousEnabledAttribute,true)
                                 .FirstOrDefault();
             if (attribute == null)
             {
                 return base.AuthorizeCore( context );
             }
             return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion
I have implemented a custom membership provider using LINQ to SQL. When I added
I have an MVC3 app using Autofac and a custom membership provider. If I
We have created a custom membership provider that we are using in one of
I'm working in a MVC3 application using Custom Membership Provider. The problem is when
I have a website with login and register forms using custom HDI Membership provider
I have a simple create user wizard and custom membership provider which was taken
I'm working with a custom asp.net membership provider in conjunction with the default Account
In an ASP.net application I'm using a Login control with a custom membership provider
I'm using standard forms authentication with my custom membership and roles providers. Everything fine,

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.