Пример #1
0
        public void Init(HttpApplication context)
        {
            context.Error += (object sender, System.EventArgs e) =>
            {
                var container = IocContainerManager.GetInstance();

                if (((container != null)) & (HttpContext.Current.Items["PerRequestScope"] == null))
                {
                    var scope = container.BeginLifetimeScope();
                    HttpContext.Current.Items["PerRequestScope"] = scope;
                }

                var       Request      = context.Request;
                var       Response     = context.Response;
                Exception currentError = context.Server.GetLastError();
                var       bllErrorInfo = new ErrorInfoService();
                var       errorInfo    = new ErrorInfo();
                //if ((SessionManager.GetUser() != null))
                //{
                //    errorInfo.UID = SessionManager.GetUser().AccountID;
                //}
                errorInfo.ErrorMsg = currentError.Message.ToString();

                if (currentError.GetType().Name == "SysDbException")
                {
                    SysDbException ex = (SysDbException)currentError;
                    errorInfo.ExecSql   = ex.SqlInfo;
                    errorInfo.ErrorCode = 1;
                }

                errorInfo.ProgramID  = "0";
                errorInfo.Url        = Request.Url.ToString();
                errorInfo.StackTrace = currentError.ToString();
                StringBuilder sb = new StringBuilder();
                Response.Clear();
                sb.Append("<h2>系统错误:</h2><hr/>系统发生错误,错误编号为:");

                if (!errorInfo.Url.Contains("/Error"))
                {
                    sb.Append(bllErrorInfo.Add(errorInfo));
                }
                //todo对于已记录的无需再记录
                sb.Append("。该信息已被系统记录,请稍后重试或与系统管理员联系。<br/>错误地址:");
                sb.Append(Request.Url.ToString());
                sb.Append("<br/>错误信息: <font class='ErrorMessage'>");
                sb.Append(currentError.Message.ToString());
                sb.Append("</font><hr/><b>Stack Trace:</b><br/>");
                sb.Append(currentError.ToString());
                Response.Write(sb.ToString());
                Response.End();
                context.Server.ClearError();
            };
        }
Пример #2
0
        //protected virtual void LogInfo(string userId, string infoMsg)
        //{
        //    var errorInfo = new ErrorInfo();
        //    errorInfo.ErrorMsg = infoMsg;
        //    errorInfo.RunningTime = System.DateTime.Now;
        //    errorInfo.Url = HttpContext.Request.Path.ToString();
        //    _errorInfoService.Add(errorInfo);
        //}

        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            //todo完善
            //创建基于http request的scope用于显式的依赖注入,eg RespositoryFactory CouDbContext的构建
            var container = IocContainerManager.GetInstance();

            if (container != null)
            {
                var scope = container.BeginLifetimeScope();
                HttpContext.Items["PerRequestScope"] = scope;
            }

            Utils.InitializeCulture();
            return(base.BeginExecuteCore(callback, state));
        }
Пример #3
0
        /// <summary>
        /// 引发 <see cref="E:System.Web.UI.Control.Init" /> 事件以对页进行初始化。
        /// </summary>
        /// <param name="e">包含事件数据的 <see cref="T:System.EventArgs" />。</param>

        protected override void OnInit(EventArgs e)
        {
            //创建基于http request的scope用于显式的依赖注入,eg RespositoryFactory CouDbContext的构建
            var container = IocContainerManager.GetInstance();

            if ((container != null))
            {
                dynamic scope = container.BeginLifetimeScope();
                HttpContext.Current.Items["PerRequestScope"] = scope;
            }

            base.OnInit(e);
            Load  += new EventHandler(PageBase_Load);
            Error += new EventHandler(PageBase_Error);
        }