1 /// <summary> 2 /// 3 /// </summary> 4 public class AjaxOnlyAttribute : ActionFilterAttribute 5 { 6 /// <summary> 7 /// Called by the ASP.NET MVC framework before the action method executes. 8 /// </summary> 9 /// <param name="filterContext">The filter context.</param> 10 public override void OnActionExecuting(ActionExecutingContext filterContext) 11 { 12 if (!filterContext.HttpContext.Request.IsAjaxRequest()) 13 { 14 filterContext.Result = new ContentResult() { Content = "只支持Ajax方法调用。", ContentEncoding = Encoding.UTF8, ContentType = "text/html" }; 15 //new HttpNotFoundResult(); 16 } 17 base.OnActionExecuting(filterContext); 18 }
相关文章: