4

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? enter image description here

3

Sitecore does not set error status codes properly. The code handling no access redirect is done on the method RedirectOnNoAccess of the processor Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel.

SXA sets the header for NotFound and 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 Context.Items["httpStatus"] to 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.

  • Thanks @josedbaez in general this is good solution. But now browser return object move here message instead of sitecore page. Do you know what to do ? Redirect at web config not help – Arbejdsglæde yesterday
  • Can you check browser console and see the URL? Is it correct? – josedbaez yesterday
  • yes I see only requested page with status 403 – Arbejdsglæde 23 hours ago
  • Problem might be that IIS is not letting the request through :S. You might need to play around with other Response settings. Try adding Response.TrySkipIisCustomErrors = true; or adding a substatuscode – josedbaez 19 hours ago
  • @josedbaex hard to do it :) not works for me in any way but any way thanks for help – Arbejdsglæde 10 hours ago

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.