Skip to content

Instantly share code, notes, and snippets.

@kevinbrechbuehl
Created November 16, 2013 16:26
Show Gist options
  • Save kevinbrechbuehl/7502152 to your computer and use it in GitHub Desktop.
Save kevinbrechbuehl/7502152 to your computer and use it in GitHub Desktop.
public class ValidateFormHandler : ActionMethodSelectorAttribute
{
/// <summary>
/// Determines whether the current action is valid for this request.
/// </summary>
/// <param name="controllerContext">The controller context.</param>
/// <param name="methodInfo">The method information.</param>
/// <returns>Boolean value if request is valid</returns>
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
string controller, action;
if (controllerContext.HttpContext.Request.HttpMethod == "POST")
{
// POST
controller = controllerContext.HttpContext.Request.Form[UnicHelper.ControllerFieldName];
action = controllerContext.HttpContext.Request.Form[UnicHelper.ActionFieldName];
}
else
{
// GET
controller = controllerContext.HttpContext.Request.QueryString[UnicHelper.ControllerFieldName];
action = controllerContext.HttpContext.Request.QueryString[UnicHelper.ActionFieldName];
}
return !string.IsNullOrWhiteSpace(controller)
&& !string.IsNullOrWhiteSpace(action)
&& controller == controllerContext.Controller.GetType().Name
&& methodInfo.Name == action;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment