Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MyApp.Web.Models
- {
- using System;
- using System.Web.Mvc;
- [AttributeUsage(AttributeTargets.Method)]
- public class AjaxOnlyAttribute : ActionFilterAttribute
- {
- public override void OnActionExecuting(ActionExecutingContext filterContext)
- {
- if (!filterContext.HttpContext.Request.IsAjaxRequest())
- {
- filterContext.HttpContext.Response.StatusCode = 404;
- filterContext.Result = new HttpNotFoundResult();
- }
- else
- {
- base.OnActionExecuting(filterContext);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement