zoukankan      html  css  js  c++  java
  • mvc 方法只允许ajax访问

    有时候我们写一些方法 只想在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 Updatehttime(string BillNo, string htStartTime, string htendTime, int totalSplitNum)

  • 相关阅读:
    Java方法
    Java程序控制
    Java基础语法
    编程语言的两大类型
    IntelliJ IDEA优化配置
    Hello World
    Java安装及卸载
    Java来龙去脉
    计算机底层基础
    Day14
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/6123434.html
Copyright © 2011-2022 走看看