Created
June 8, 2016 12:38
-
-
Save Kashkovsky/e672a568177eedfb77e670ffab7a2ca7 to your computer and use it in GitHub Desktop.
Namespace constraint attribute
This file contains hidden or 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 NamespaceConstraint : ActionMethodSelectorAttribute | |
{ | |
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) | |
{ | |
var dataTokenNamespace = (string)controllerContext.RouteData.DataTokens.FirstOrDefault(dt => dt.Key == "Namespace").Value; | |
var actionNamespace = methodInfo?.DeclaringType?.FullName; | |
return dataTokenNamespace == actionNamespace; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment