ASP.NET MVC 5: “Authorization” by default for your web app

Securing your MVC app is a tricky business! Although security is a huge topic, one of the problems that you might encounter is that unauthenticated users are allowed by default to execute every action in your web app. That behaviour is potentially unsafe because you have to remember to decorate your actions with the authorize attribute, and humans are prone to errors!

This is why, in my opinion, authentication should be enforced by default, or differently [Authorize] attribute should be added behind the scenes to every action.

Thankfully, you can use global filters to do that!
Open App_Start folder, double click on FilterConfig.cs and add as a global filter the AuthorizeAttribute() like this:

This way, every controller and action needs authorization before executing its code. The only thing you have to remember, is to allow access wherever you want (e.g. login actio ) using the AllowAnonymous attribute: