1
我想爲多站點/多語言實現500錯誤頁面,我正在關注this article。500自定義錯誤頁面
但Global.asax中的Application_Error
未觸發。這裏是我的代碼:
<%@ Application Language='C#' Inherits="Sitecore.ContentSearch.SolrProvider.CastleWindsorIntegration.WindsorApplication" %>
<script RunAt="server">
private void Application_Error(object sender, EventArgs e)
{
var customErrorsSection = (System.Web.Configuration.CustomErrorsSection)ConfigurationManager.GetSection("system.web/customErrors");
var lastException = Server.GetLastError();
if (customErrorsSection.Mode != System.Web.Configuration.CustomErrorsMode.Off)
{
try
{
// Log.Error("There was an error in the application", lastException);
Server.ClearError();
HttpContext.Current.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
Server.Transfer(string.Format("/Error/{0}_500.html", GetSafeLanguage()));
}
catch
{
}
}
}
private string GetSafeLanguage()
{
try
{
return Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName;
}
catch
{
}
return string.Empty;
}
</script>
我可以看到這些潛在的問題:1)'RunAt'應該是spel以'runat'爲首; 2)確保'WindsorApplication'類繼承自'System.Web.HttpApplication'; 3)嘗試將你的方法放入Global.asax.cs中的類中,而不是在Global.asax中的'