Search code examples
asp.net-coreasp.net-core-mvcauthorizationauthorize-attribute

Authorize attribute on entire project in .net mvc for security


I am applying authorize attibutes on each classes.

So is it possible to avoid this, and secure my entire web application at once?

Something like at "Namespace" level?

I am using .net core mvc application.


Solution

  • None of the above worked. But I got the solution. So following worked for me.

    services.AddMvc(config =>
                {
                    var policy = new AuthorizationPolicyBuilder()
                                 .RequireAuthenticatedUser()
                                 .Build();
                    config.Filters.Add(new AuthorizeFilter(policy));
                });