Skip to content

Instantly share code, notes, and snippets.

@fmshk97
Created February 21, 2021 10: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 fmshk97/775df494cf2f23b4564c0190282694fa to your computer and use it in GitHub Desktop.
Save fmshk97/775df494cf2f23b4564c0190282694fa to your computer and use it in GitHub Desktop.
Configuration for returning appropriate HTTP status codes if user unauthorized
services.AddAuthentication(defaultScheme: CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
options.Events.OnRedirectToAccessDenied = ReplaceRedirector(HttpStatusCode.Forbidden, options.Events.OnRedirectToAccessDenied);
options.Events.OnRedirectToLogin = ReplaceRedirector(HttpStatusCode.Unauthorized, options.Events.OnRedirectToLogin);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment