Created
May 2, 2013 13:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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