I found a similar question, but could not find out what I need from there
I am trying to achieve a language-specific, content manageable, friendly error message page for 500 status code.
What I have done so far is:
- Added a new processor in
httpRequestEnd
pipeline afterSitecore.Pipelines.HttpRequest.EndDiagnostics
- Finding if there is any internal server error.
If there is, getting error Item from sitecore.
public class Handle500Erros : HttpRequestProcessor { public override void Process(HttpRequestArgs args) { if (args?.Context?.Response.StatusCode == (int)HttpStatusCode.InternalServerError) { var errorPageItem = Sitecore.Context.Database.GetItem(string.Concat(Sitecore.Context.Site.StartPath, Settings.ErrorPage)); if (errorPageItem!= null && Sitecore.Context.Item.ID!= errorPageItem.ID) { Sitecore.Context.Item = errorPageItem; //var htmlForErrorPageForSpecificlanguage = GetHtmlforErrorItem // set response html to htmlForErrorPageForSpecificlanguage } } } }
Let's assume my error Item name in sitecore is 500Error
Now my question is:
- How to get Html for the error sitecore Item?
- How to write that to response, seems like
args.Context.Response
is readonly?
So if some error comes up at 500Error item I am just skipping this step, so there won't be any infinite loops happening.
Am I over complicating? is there a better way to do this?