Sitecore Multi-Site custom 500 error page
Sitecore Multi-Site custom 500 error page
This post is an add on to my previous post Secure Sitecore : Why use a custom 500 error page? In this post I will go through how you can get a multi-site custom 500 error page in a Sitecore solution.
This would mean that each site in your Sitecore instance can have it’s individualized custom 500 error page. As I mentioned before, I truly believe it makes absolute sense to have a static 500 error page rather than on inside of Sitecore for obvious reasons.
A version of this code exists in production environments and has been working like a charm.
First, we need to add Global.asax because we need to process Application_Error event. Second, try not to use any Sitecore API in this file.
We added an AppSettings config flag to control the processing. In your web.config add the following to the AppSettings section:
You would also need to make a few changes in the Web.config. First add in the httpErrors node in :
Also set the customErrors mode as On.
Next we need to add the Application_Error event in the global.asax.cs file. Here is a sample below:
https://xchangesitecore.com/sitecore-multi-site-custom-500-error-page/ Vikash Raaj
This would mean that each site in your Sitecore instance can have it’s individualized custom 500 error page. As I mentioned before, I truly believe it makes absolute sense to have a static 500 error page rather than on inside of Sitecore for obvious reasons.
A version of this code exists in production environments and has been working like a charm.
First, we need to add Global.asax because we need to process Application_Error event. Second, try not to use any Sitecore API in this file.
We added an AppSettings config flag to control the processing. In your web.config add the following to the AppSettings section:
1  | <add key="Show500PagePerSite" value="true" />  | 
You would also need to make a few changes in the Web.config. First add in the httpErrors node in :
1  | <httpErrors existingResponse="PassThrough" />  | 
Also set the customErrors mode as On.
Next we need to add the Application_Error event in the global.asax.cs file. Here is a sample below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  | using System; using System.Configuration; using System.Web; namespace YOURNAMESPACE {     public class Global : Sitecore.Web.Application     {         protected void Application_Error(object sender, EventArgs e)         {             var lastException = Server.GetLastError();             bool show500page = !string.IsNullOrEmpty(ConfigurationManager.AppSettings["Show500PagePerSite"]) && ConfigurationManager.AppSettings["Show500PagePerSite"].ToLower().Equals("true") ? true : false;             if (show500page)             {                 HttpContext.Current.Server.ClearError();                 HttpContext.Current.Response.Clear();                 HttpContext.Current.Response.TrySkipIisCustomErrors = true;                 HttpContext.Current.Response.StatusCode = 500;                 HttpContext.Current.Response.StatusDescription = "500 Internal Server Error";                 Server.Transfer(GetSitePath(HttpContext.Current.Request.Url.GetComponents(UriComponents.Host, UriFormat.Unescaped))); // set the redirect location             }         }         private string GetSitePath(string hostname)         {             if (hostname.Contains("FIRSTSITEHOST")) return "/errors/FIRSTSITEERRORPAGENAME.html";             if (hostname.Contains("SECONDSITEHOST")) return "/errors/SECONDSITEERRORPAGENAME.html";             return "/";         }     } }  | 
https://xchangesitecore.com/sitecore-multi-site-custom-500-error-page/ Vikash Raaj
Comments
Post a Comment