"Cannot redirect after HTTP headers have been sent" error while redirecting to login page

  • Errors might occur if a logged-in user tries to perform a new request after a period of inactivity. For example, if a logged-in user has not been doing anything on the Sitecore Launchpad for some time and tries to open any application after the user session has expired.
    The following MVC errors can be found in the log records:
    4132 13:08:18 INFO  AUDIT (sitecore\**): Logout
    4132 13:08:18 WARN  Protected page accessed with no current user
    4132 13:08:18 ERROR Failed to render rendering
    Exception: System.InvalidOperationException
    Message: Error while rendering view: '/sitecore/shell/client/Speak/Layouts/Renderings/Common/PageCodes/PageCode.cshtml' (model: 'Sitecore.Mvc.Presentation.RenderingModel, Sitecore.Mvc').
    Source: Sitecore.Mvc
       at Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)
       at Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args)
    Nested Exception
    Exception: System.Web.HttpException
    Message: Cannot redirect after HTTP headers have been sent.
    Source: System.Web
       at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
       at Sitecore.Shell.Web.ShellPage.GotoLoginPage(HttpContext httpContext, Boolean returnAfterLogin)
      ... 4132 13:08:18 ERROR Failed to render rendering
    Exception: System.InvalidOperationException
    Message: Error while rendering view: '/sitecore/shell/client/Speak/Layouts/Layouts/Speak-Layout.cshtml' (model: 'Sitecore.Mvc.Presentation.RenderingModel, Sitecore.Mvc').
    Source: Sitecore.Mvc
      ...

Applies to:

CMS 8.2 Initial Release - 9.2 Initial Release

CMS 9.3 Initial Release

March 13, 2020
September 28, 2020

Reference number:

101417