码迷,mamicode.com
首页 > Web开发 > 详细

mvc 方法只允许ajax访问

时间:2016-12-01 22:02:59      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:tar   rtti   set   system   art   string   target   override   selector   

有时候我们写一些方法 只想在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)

 

mvc 方法只允许ajax访问

标签:tar   rtti   set   system   art   string   target   override   selector   

原文地址:http://www.cnblogs.com/lyl6796910/p/6123434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!