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.
精彩评论