Skip to content

Instantly share code, notes, and snippets.

@mikanyg
Last active May 2, 2017 22:37
Show Gist options
  • Save mikanyg/0cecb7f5c28c4f008394bed783356222 to your computer and use it in GitHub Desktop.
Save mikanyg/0cecb7f5c28c4f008394bed783356222 to your computer and use it in GitHub Desktop.
WebApi ActionFilter used in conjunction with Service Fabric reverse proxy or ServiceFabric.AutoRest to indicate a RESTfull 404 response.
using System;
using System.Net;
using System.Web.Http.Filters;
namespace ServiceFabric.WebApi.Filters
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class ResourceNotFoundAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
if (actionExecutedContext?.Response.StatusCode == HttpStatusCode.NotFound)
{
actionExecutedContext.Response.Headers.Add("X-ServiceFabric", "ResourceNotFound");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment