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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:03:11+00:00 2026-06-12T15:03:11+00:00

I have a web application which is secured down by Windows authentication. However, I

  • 0

I have a web application which is secured down by Windows authentication. However, I have one controller which needs to be available globally to anyone, so they do not need a Windows account on the server to be granted access.

I have got this to work by enabling both Windows authentication, and Anonymous Authentication in IIS. My controllers now look like this:

[Authorize]
public class MyController : Controller
{
    public Index()
    {
    }

    public DoStuff()
    {
    }

    etc...
}

My anonymous controller is the same, except I have removed the [Authorise] attribute from the start of it.

Am I right in saying that this instructs the web application to only allow those users with a Windows account to use the majority of controllers, except for the controller which I want to allow anonymous access to?

It seems to work just fine, but I wanted to ensure I have not left a gaping security hole open by doing this?

Are there any issues with enabling both methods of authentication, and setting the application up in this way?

  • 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-12T15:03:13+00:00Added an answer on June 12, 2026 at 3:03 pm

    First of all, the way you are doing it, there is no gaping hole in the security of your application and it will behave the way you are anticipating. But there is a better way …

    The problem with Authorize attribute is that it’s easy to forget to the new controller you add to your application and if you don’t add it, your controller is open to the public.

    If you were using MVC 4, you could add the Authorize attribute as a global filter and then use AllowAnonymous attribute on your anonymous controller(s) because Authorize attribute respects AllowAnonymous attribute by Default. MVC 3, on the other hand, doesn’t ship with AllowAnonymous attribute. T

    The way around is to create the AllowAnonymous attribute yourself in your project like so:

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public sealed class AllowAnonymousAttribute : Attribute { }
    

    Now, you can subclass from the built in Authorize attribute to customize that and look for Anonymous attribute applied to your controller. If you find the attribute, you can skip the authorization. Here is an example implementation:

    public sealed class AuthorizeWithAnonymousSupportAttribute : AuthorizeAttribute
        {
            public override void OnAuthorization(AuthorizationContext filterContext)
            {
                bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)
                || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true);
                if (!skipAuthorization)
                {
                    base.OnAuthorization(filterContext);
                }
            }
        }
    

    You will have to add this attribute to the global filters of your site. In your Global.asax:

    public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
        filters.Add(new AuthorizeWithAnonymousSupportAttribute ());
        filters.Add(new HandleErrorAttribute());
    }
    

    Now, the last step. You can simply add the AllowAnonymous attribute to any controller you want to be anonymous:

    [AllowAnonymous]
    public class MyController : Controller
    {
        public Index()
        {
        }
    
        public DoStuff()
        {
        }
    
        etc...
    }
    

    The benefit of doing all of the above is that you don’t have to worry about putting Authorize attribute to the controllers you add to your application. Instead, you will have to explicitly tell the application which controllers are open to the public.

    Thanks and hope this helps.

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

Sidebar

Related Questions

I have a web application which needs to perform a file copy operation and
I have one web application which I have been working for some time.I am
We are working on a GWT web-application which requires secure user authentication. We have
I have a web application which contains both secure (SSL) and non-secure pages. A
I have web application which we deployed in a production . We have separate
I have web application of which major part is javascript. I request images from
I have a web application which process the data collected from different client machines
I have a web application which uses the globalization values being passed from sql
I have a web application which is deployed by the means of Flask. I'm
Using JDeveloper as my IDE, I have a web application which calls services provided

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.