Created
November 16, 2013 16:26
-
-
Save kevinbrechbuehl/7502152 to your computer and use it in GitHub Desktop.
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
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