I have Sitecore 8.2 with SXA, I need to change page status code in case user is not login, but try to open some pages only for login users. Basically Sitecore works ok, I could be redirected to login page depending on settings and etc. but the question is next why Sitecore return 302 status code ? How to change it to 403 at most proper way?
Sitecore does not set error status codes properly. The code handling no access redirect is done on the method
RedirectOnNoAccess of the processor
SXA sets the header for
InternalServerError, but not for
Forbidden. This is done via processor
Sitecore.XA.Feature.ErrorHandling.Pipelines.HtpRequestProcessed.SetStatusCode. Use a decompiler to see the code.
You could override
RedirectOnNoAccess to set
HttpStatusCode.Forbidden and then override the
Process method on
SetStatusCode so the switch included a check for
HttpStatusCode.Forbidden and sets the StatusCode to 403.