Beispiel #1
0
        /// <summary>
        /// 全局的异常处理
        /// </summary>
        public void ExceptionHandlerStarter()
        {
            SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));

            if (siteConfig.globalexceptionstatus == 1)
            {
                string            s      = HttpContext.Current.Request.Url.ToString();
                HttpServerUtility server = HttpContext.Current.Server;
                if (server.GetLastError() != null)
                {
                    Exception lastError = server.GetLastError();
                    // 此处进行异常记录,可以记录到数据库或文本,也可以使用其他日志记录组件。
                    ExceptionHander.WriteException(lastError);
                    Application["LastError"] = lastError;
                    int    statusCode        = HttpContext.Current.Response.StatusCode;
                    string exceptionOperator = siteConfig.globalexceptionurl;
                    try
                    {
                        if (!String.IsNullOrEmpty(exceptionOperator))
                        {
                            exceptionOperator = new System.Web.UI.Control().ResolveUrl(exceptionOperator);
                            string url    = string.Format("{0}?ErrorUrl={1}", exceptionOperator, server.UrlEncode(s));
                            string script = String.Format("<script language='javascript' type='text/javascript'>window.top.location='{0}';</script>", url);
                            Response.Write(script);
                            Response.End();
                        }
                    }
                    catch { }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="oper">操作人</param>
        /// <param name="mes">操作信息</param>
        /// <param name="result">结果</param>
        /// <param name="type">类型</param>
        /// <param name="module">操作模块</param>
        public static void WriteServiceLog(string oper, string mes, string result, string type, string module)
        {
            SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));

            //后台管理日志开启
            if (siteConfig.logstatus == 1)
            {
                ValidationErrors errors = new ValidationErrors();
                SysLog           entity = new SysLog();
                entity.Id         = ResultHelper.NewId;
                entity.Operator   = oper;
                entity.Message    = mes;
                entity.Result     = result;
                entity.Type       = type;
                entity.Module     = module;
                entity.CreateTime = ResultHelper.NowTime;
                using (SysLogRepository logRepository = new SysLogRepository(new DBContainer()))
                {
                    logRepository.Create(entity);
                }
            }
            else
            {
                return;
            }
        }
Beispiel #3
0
        public static void WriteWeChatLog(WC_ResponseLogModel model)
        {
            SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));

            //后台管理日志开启
            if (siteConfig.logstatus == 1)
            {
                WC_ResponseLog entity = new WC_ResponseLog();
                entity.Id              = ResultHelper.NewId;
                entity.OpenId          = model.OpenId;
                entity.RequestType     = model.RequestType;
                entity.RequestContent  = model.RequestContent;
                entity.ResponseType    = model.ResponseType;
                entity.ResponseContent = model.ResponseContent;
                entity.CreateBy        = "";
                entity.CreateTime      = ResultHelper.NowTime;
                entity.ModifyBy        = "";
                entity.ModifyTime      = ResultHelper.NowTime;

                using (WC_ResponseLogRepository logRepository = new WC_ResponseLogRepository(new DBContainer()))
                {
                    logRepository.Create(entity);
                }
            }
            else
            {
                return;
            }
        }
Beispiel #4
0
        protected void Application_Start()
        {
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            AreaRegistration.RegisterAllAreas();
            #if DEBUG
            BundleTable.EnableOptimizations = false; //关闭文件压缩功能
            #else
            BundleTable.EnableOptimizations = true;  //开启文件压缩功能
            #endif
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));
            //启动任务调度系统
            if (siteConfig.taskstatus == 1)
            {
                StartScheduler();
            }

            //注入 Ioc
            // var container = new UnityContainer();
            UsingUnityContainer.Init();
            DependencyRegisterType.Container_Sys(ref UsingUnityContainer._container);
            DependencyRegisterType.Container_Mis(ref UsingUnityContainer._container);
            DependencyRegisterType.Container_Def(ref UsingUnityContainer._container);
            DependencyRegisterType.Container_Flow(ref UsingUnityContainer._container);
            DependencyRegisterType.Container_Sql(ref UsingUnityContainer._container);
            DependencyResolver.SetResolver(new UnityDependencyResolver(UsingUnityContainer._container));
        }
 /// <summary>
 /// 加入异常日志
 /// </summary>
 /// <param name="ex">异常</param>
 public static void WriteException(Exception ex)
 {
     Apps.Models.Sys.SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));
     //后台异常开启
     if (siteConfig.exceptionstatus == 1)
     {
         try
         {
             using (DBContainer db = new DBContainer())
             {
                 SysException model = new SysException()
                 {
                     Id         = ResultHelper.NewId,
                     HelpLink   = ex.HelpLink,
                     Message    = ex.Message,
                     Source     = ex.Source,
                     StackTrace = ex.StackTrace,
                     TargetSite = ex.TargetSite.ToString(),
                     Data       = ex.Data.ToString(),
                     CreateTime = ResultHelper.NowTime
                 };
                 db.SysException.Add(model);
                 db.SaveChanges();
             }
         }
         catch (Exception ep)
         {
             string subFold  = DateTime.Now.Year + DateTime.Now.Month.ToString("D2");
             string fileName = subFold + DateTime.Now.Day.ToString("D2") + ".txt";
             string path     = System.Web.HttpContext.Current.Server.MapPath("~/LogFile/") + subFold;
             if (!Directory.Exists(path))
             {
                 Directory.CreateDirectory(path);
             }
             string wholePath = path + "\\" + fileName;
             using (StreamWriter sw = new StreamWriter(wholePath, true, Encoding.UTF8))
             {
                 sw.WriteLine((ex.Message + "|" + ex.StackTrace + "|" + ep.Message + "|" + DateTime.Now.ToString()).ToString());
                 sw.Dispose();
                 sw.Close();
             }
             return;
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// 验证是否有单机限制
        /// </summary>
        /// <param name="account">用户信息</param>
        /// <returns>验证结果:true有限制,false没有</returns>
        public static bool ValidateRelogin(AccountModel account)
        {
            bool bResult = false;

            if (account != null)
            {
                SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));
                if (siteConfig.issinglelogin == 1)
                {
                    if (IsChange(HttpContext.Current.Session.SessionID, account.Id))
                    {
                        //同一帐号已经在其他机子登录
                        bResult = true;
                        RedirectUrl();
                    }
                }
            }
            return(bResult);
        }
Beispiel #7
0
 /// <summary>
 /// 加入异常日志
 /// </summary>
 /// <param name="ex">异常</param>
 public static void WriteException(Exception ex)
 {
     Apps.Models.Sys.SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));
     //后台异常开启
     if (siteConfig.exceptionstatus == 1)
     {
         try
         {
             using (DBContainer db = new DBContainer())
             {
                 SysException model = new SysException()
                 {
                     Id         = ResultHelper.NewId,
                     HelpLink   = ex.HelpLink,
                     Message    = ex.Message,
                     Source     = ex.Source,
                     StackTrace = ex.StackTrace,
                     TargetSite = ex.TargetSite.ToString(),
                     Data       = ex.Data.ToString(),
                     CreateTime = ResultHelper.NowTime
                 };
                 db.SysException.Add(model);
                 db.SaveChanges();
             }
         }
         catch (Exception ep)
         {
             try
             {
                 string path    = @"~/exceptionLog.txt";
                 string txtPath = System.Web.HttpContext.Current.Server.MapPath(path);    //获取绝对路径
                 using (StreamWriter sw = new StreamWriter(txtPath, true, Encoding.Default))
                 {
                     sw.WriteLine((ex.Message + "|" + ex.StackTrace + "|" + ep.Message + "|" + DateTime.Now.ToString()).ToString());
                     sw.Dispose();
                     sw.Close();
                 }
                 return;
             }
             catch { return; }
         }
     }
 }
Beispiel #8
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            #if DEBUG
            BundleTable.EnableOptimizations = false; //关闭文件压缩功能
            #else
            BundleTable.EnableOptimizations = true;  //开启文件压缩功能
            #endif
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            SysConfigModel siteConfig = new Apps.BLL.SysConfigBLL().loadConfig(Utils.GetXmlMapPath("Configpath"));
            //启动任务调度系统
            if (siteConfig.taskstatus == 1)
            {
                StartScheduler();
            }

            UnityConfig.RegisterComponents();
        }