ASP.NET MVC(Action Filter)
public class AdminController : Controller { // … instance variables and constructor public ViewResult Index() { if (!Request.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); } // …rest of action method } public ViewResult Create() { if (!Request.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); } // …rest of action method } … AdminController控制器的众多Action中我们都需要判定当前验证用户,这里有很多重复的代码,我们可以简化为: [Authorize] public class AdminController : Controller { // … instance variables …
