Skip to content

Instantly share code, notes, and snippets.

@Kashkovsky
Created June 8, 2016 12:38
Show Gist options
  • Save Kashkovsky/e672a568177eedfb77e670ffab7a2ca7 to your computer and use it in GitHub Desktop.
Save Kashkovsky/e672a568177eedfb77e670ffab7a2ca7 to your computer and use it in GitHub Desktop.
Namespace constraint attribute
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