asp.net mvc Adding to the AUTHORIZE attribute
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I create a custom attribute to extend existing Authorize attribute in MVC? 回答1: Derive your class from AuthorizeAttribute. Override the OnAuthorization method. Add and set up a CacheValidationHandler. public void CacheValidationHandler( HttpContext context, object data, ref HttpValidationStatus validationStatus ) { validationStatus = OnCacheAuthorization( new HttpContextWrapper( context ) ); } public override void OnAuthorization( AuthorizationContext filterContext ) { if (filterContext == null) { throw new ArgumentNullException(