using System; using System.Web.Mvc; namespace Learun.Application.Web { /// /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架 /// Copyright (c) 2013-2018 Hexagon PPM /// 创建人:研发部 /// 日 期:2017.03.08 /// 描 述:仅允许Ajax操作 /// [AttributeUsage(AttributeTargets.Method)] public class AjaxOnlyAttribute : ActionMethodSelectorAttribute { /// /// 初始化仅允许Ajax操作 /// /// 跳过Ajax检测 public AjaxOnlyAttribute(bool ignore = false) { Ignore = ignore; } /// /// 跳过Ajax检测 /// public bool Ignore { get; set; } /// /// 验证请求有效性 /// /// 控制器上下文 /// 方法 public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo) { if (Ignore) return true; return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest(); } } }