Skip to content

Instantly share code, notes, and snippets.

@bgrins
Created May 2, 2013 13:13
Show Gist options
  • Save bgrins/5502076 to your computer and use it in GitHub Desktop.
Save bgrins/5502076 to your computer and use it in GitHub Desktop.
Prevent all non GET/POST requests in a base controller class in asp mvc
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
string httpMethod = filterContext.RequestContext.HttpContext.Request.HttpMethod.ToUpper();
// Prevent all non GET/POST requests
if (httpMethod != "GET" && httpMethod != "POST")
{
filterContext.Result = new HttpStatusCodeResult(404);
return;
}
else
{
base.OnActionExecuting(filterContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment