Skip to content

Instantly share code, notes, and snippets.

@pranavkm
Created May 29, 2014 19:31
Show Gist options
  • Save pranavkm/c0185df32933fb5b3ea6 to your computer and use it in GitHub Desktop.
Save pranavkm/c0185df32933fb5b3ea6 to your computer and use it in GitHub Desktop.
public static void Register(HttpConfiguration config)
{
config.Services.Add(typeof(System.Web.Http.ValueProviders.ValueProviderFactory),
new EmptyValueProviderFactory());
}
public class EmptyValueProvider : System.Web.Http.ValueProviders.IValueProvider
{
public bool ContainsPrefix(string prefix)
{
return prefix != null && prefix.Length == 0;
}
public System.Web.Http.ValueProviders.ValueProviderResult GetValue(string key)
{
return null;
}
}
public class EmptyValueProviderFactory : System.Web.Http.ValueProviders.ValueProviderFactory,
System.Web.Http.ValueProviders.IUriValueProviderFactory
{
private static readonly EmptyValueProvider _valueProvider = new EmptyValueProvider();
public override System.Web.Http.ValueProviders.IValueProvider GetValueProvider(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.ControllerContext.RouteData.Values.Count == 0)
{
return _valueProvider;
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment