2
我一直在學習如何保護asp.net MVC4應用,但一些混淆了我關於使用AuthorizeAttribute保護MVC4與AuthorizeAttribute
(其中一個是很好的解釋了MVC固定爲this one的博客)
若要鎖定默認所有控制器,所述AuthorizeAttribute加到RegisterGlobalFilters
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new System.Web.Mvc.AuthorizeAttribute());
}
但我也看到有類似的東西在Global.asax文件做例子:
GlobalConfiguration.Configuration.Filters.Add(new System.Web.Http.AuthorizeAttribute());
我明白,第一個語句來鎖定MVC控制器和第二個是鎖定的WebAPI控制器,但是什麼時候需要第二個語句?如果我不構建WebApi控制器,是否還需要第二個聲明?