Skip to content

Instantly share code, notes, and snippets.

@srkirkland
Created July 1, 2020 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srkirkland/431d2480b53d7ab7153cd71fdfabf052 to your computer and use it in GitHub Desktop.
Save srkirkland/431d2480b53d7ab7153cd71fdfabf052 to your computer and use it in GitHub Desktop.
return 403 instead of redirect for API
.AddCookie(cookies =>
{
cookies.Events.OnRedirectToAccessDenied = ctx =>
{
if (ctx.Request.Path.StartsWithSegments("/api"))
{
ctx.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return Task.CompletedTask;
}
return cookies.Events.OnRedirectToAccessDenied(ctx);
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment