atbebtg
atbebtg

Reputation: 4083

Where to put filter, attribute and extension in ASP.NET MVC

I just got done reading Rick Anderson's article on Securing your ASP.NET MVC application. In the article he talked about creating new filter attributes.

public class LogonAuthorize : AuthorizeAttribute 
{
     public override void OnAuthorization(AuthorizationContext filterContext) 
     {
         if (!(filterContext.Controller is AccountController))
             base.OnAuthorization(filterContext);
     }
}

and

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

My question is, what is the best way to organize these filters and attributes? Do I create a new class file for each? Do I create one class file for all filter and attribute? Where is the best place to put it? In the root folder? in subfolder?

Upvotes: 2

Views: 2697

Answers (1)

Shane Courtrille
Shane Courtrille

Reputation: 14097

We have an MVCFilters directory and each attribute filter would get its own class.

And if we started to create a lot of custom filters we might break them up into sub directories like security and whatever else we had.

Upvotes: 3

Related Questions