When I specify 404 as a http result code, UseStatusCodePagesWithReExecute
is working like expected.
When I specify 403 as a http result code, <
Figured it out, thanks to @Kirk
Adding this code to AddCookie
does the trick.
options.Events.OnRedirectToAccessDenied = context =>
{
context.Response.StatusCode = 403;
return Task.CompletedTask;
};
This is the original event handler method, I don't care the Location
header, so I have omitted the related code, you may not want to.
public Func<RedirectContext<CookieAuthenticationOptions>, Task> OnRedirectToAccessDenied { get; set; } = (Func<RedirectContext<CookieAuthenticationOptions>, Task>) (context =>
{
if (CookieAuthenticationEvents.IsAjaxRequest(context.Request))
{
context.Response.Headers["Location"] = (StringValues) context.RedirectUri;
context.Response.StatusCode = 403;
}
else
context.Response.Redirect(context.RedirectUri);
return Task.CompletedTask;
});