有时候我们写一些方法 只想在ajax使用  其他的不想暴露  就可以对方法进行限制

 定义一个类

    [AttributeUsage(AttributeTargets.Method)]
    public class HandlerAjaxOnlyAttribute : ActionMethodSelectorAttribute
    {
        public bool Ignore { get; set; }
        public HandlerAjaxOnlyAttribute(bool ignore = false)
        {
            Ignore = ignore;
        }
        public override bool IsValidForRequest(ControllerContext controllerContext, 
System.Reflection.MethodInfo methodInfo) {
if (Ignore) return true; return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest(); } }

调用方法 如下

[HandlerAjaxOnly]
public ActionResult yourActionName(string item1, string item2)

{}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2021-11-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-18
  • 2021-08-04
  • 2021-10-31
相关资源
相似解决方案