-
-
Save LSTANCZYK/c7888a37f213ef06d87241878547b62f 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 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
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