Пример #1
0
        /// <summary>
        /// 添加错误信息
        /// </summary>
        private static void AddErrorEntity(Exception ex)
        {
            ex = ex == null && HttpContext.Current != null?HttpContext.Current.Server.GetLastError() : ex;

            if (!CheckSave(ex))
            {
                return;
            }
            var info = new ErrorEntity
            {
                Address  = HttpContext.Current.Request.Url.ToString(),
                Device   = HttpContext.Current.Request.UserAgent,
                Ip       = GetClientIp(),
                SaveType = SaveType.Add
            };

            info.SetEntity(ex);
            FillIdentity(info);
            Ioc.Resolve <IApplicationService, ErrorEntity>().Save(info);
            if (ConfigurationManager.GetSetting <bool>("IsDebug"))
            {
                throw ex;
            }
            var url = UrlExtension.GetUrl(null, "PresentationAdminHomeUrl");

            HttpContext.Current.Response.Redirect(string.Format("{0}/Errors/Generic.htm", url));
        }
Пример #2
0
        /// <summary>
        /// 检查是否存储
        /// </summary>
        /// <returns></returns>
        private static bool CheckSave(Exception ex)
        {
            if (HttpContext.Current == null)
            {
                return(false);
            }
            if (ex == null)
            {
                return(false);
            }
            var exception = ex as HttpException;

            if (exception == null)
            {
                return(true);
            }
            var statusCode = exception.GetHttpCode().ToString(CultureInfo.InvariantCulture);
            var url        = UrlExtension.GetUrl(null, "PresentationAdminHomeUrl");

            switch (statusCode)
            {
            case "403":
                HttpContext.Current.Response.Redirect(string.Format("{0}/Errors/403.htm", url));
                break;

            case "404":
                HttpContext.Current.Response.Redirect(string.Format("{0}/Errors/404.htm", url));
                break;

            case "500":
                var runTime = (HttpRuntimeSection)WebConfigurationManager.GetSection("system.web/httpRuntime");
                if (runTime == null)
                {
                    return(true);
                }
                int maxRequestLength = (runTime.MaxRequestLength) * 1024;
                if (HttpContext.Current.Request.ContentLength > maxRequestLength)
                {
                    HttpContext.Current.Response.Redirect(string.Format("{0}/Errors/413.htm", url));
                    return(false);
                }
                if (ex.Message == "Version Expired")
                {
                    HttpContext.Current.Response.Redirect(string.Format("{0}/Errors/VersionExpired.htm", url));
                    return(false);
                }
                return(true);
            }
            return(false);
        }