Last active
May 2, 2017 22:37
-
-
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.
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
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