500个自定义错误页面

时间:2016-05-10 05:25:37

标签: sitecore sitecore8 sitecore-mvc sitecore8.1

我想为多站点/多语言实现500错误页面,我正在关注this article

但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>

0 个答案:

没有答案