开发者

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 eac开发者_开发知识库h? 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜