Exemple #1
0
 public static void Error(string clientUser, string requestUri, string action, object message, Exception t = null)
 {
     if (t == null)
     {
         logmonitor.Error(GetIP(), clientUser, requestUri, action, message);
     }
     else
     {
         logmonitor.Error(GetIP(), clientUser, requestUri, action, message, t);
     }
 }
Exemple #2
0
 public static void Error(string ErrorMsg, Exception ex = null)
 {
     if (ex != null)
     {
         logerror.Error(ErrorMsg, ex);
     }
     else
     {
         logerror.Error(ErrorMsg);
     }
 }
Exemple #3
0
        /// <summary>
        /// 向日志文件写入出错信息
        /// </summary>
        /// <param name="className">类名</param>
        /// <param name="ex">异常对象</param>
        public static void Error(string className, Exception ex)
        {
            var     methodinfo = SystemModule();
            IExtLog extLog     = ExtLogManager.GetLogger(dblog);

            extLog.Error(className, ex);
        }
Exemple #4
0
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            if (!filterContext.ExceptionHandled)
            {
                string controllerName = (string)filterContext.RouteData.Values["controller"];
                string actionName     = (string)filterContext.RouteData.Values["action"];
                string msg            = filterContext.Exception.Message;

                log.Error(Utils.GetIP(), CurrUser.UserName, "", controllerName + "/" + actionName, msg);
            }

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                Response response = new Response();
                response.Code    = 0;
                response.Message = "服务器出现异常,请联系管理员查看日志!";
                //filterContext.Result = new JsonResult() { Data = response };
                string re = "{Code:0,Message:'服务器出现异常,请联系管理员查看日志!'}";
                filterContext.HttpContext.Response.ContentType = "application/json";
                filterContext.HttpContext.Response.Write(re);
                filterContext.HttpContext.Response.Flush();
                filterContext.HttpContext.Response.End();
                //filterContext.HttpContext.Response.
            }
            else
            {
                base.OnException(filterContext);
                filterContext.HttpContext.Response.Redirect("/Error.html");
            }
        }
Exemple #5
0
        /// <summary>
        /// 向日志文件写入出错信息
        /// </summary>
        /// <param name="className">类名</param>
        /// <param name="content">错误信息</param>
        public static void Error(string className, string content)
        {
            var     methodinfo = SystemModule();
            IExtLog extLog     = ExtLogManager.GetLogger(dblog);
            string  url        = "";

            if (HttpContext.Current != null)
            {
                url = HttpContext.Current.Request.Url.ToString();
            }
            extLog.Error(GetIPAddress(), methodinfo, url, className, content);
        }
Exemple #6
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="email"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        //[ValidateAntiForgeryToken]
        public ActionResult UserLogin(string email, string pwd)
        {
            var json = new JsonHelper()
            {
                Msg = "", Status = ""
            };

            try
            {
                var user = userManage.UserLogin(email, pwd);
                if (user != null)
                {
                    if (user.UserStatu == "1")
                    {
                        json.Msg = "用户状态已经被锁定,请联系管理员进行解锁";
                        log.Warn(Utils.GetIP(), user.UserEmail, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg);
                        return(Json(json));
                    }
                    json.Msg    = "登录成功";
                    json.Status = "Y";
                    log.Info(Utils.GetIP(), user.UserEmail, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg);
                    return(RedirectToAction("index", "Home"));
                }
                else
                {
                    json.Msg = "密码错误或者用户名错误";
                    log.Error(Utils.GetIP(), email, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg);
                    return(Json(json));
                }
            }
            catch (Exception e)
            {
                json.Msg = e.Message;
                log.Error(Utils.GetIP(), email, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg);
            }
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #7
0
        /// <summary>
        /// 操作日志
        /// </summary>
        public void WriteLog(Common.Enums.enumOperator action, string message, Common.Enums.enumLog4net logLevel)
        {
            switch (logLevel)
            {
            case Common.Enums.enumLog4net.INFO:
                _log.Info(Utils.GetIP(), this.CurrentUser.Name, Request.Url.ToString(), action.ToString(), message);
                break;

            case Common.Enums.enumLog4net.WARN:
                _log.Warn(Utils.GetIP(), this.CurrentUser.Name, Request.Url.ToString(), action.ToString(), message);
                break;

            default:
                _log.Error(Utils.GetIP(), this.CurrentUser.Name, Request.Url.ToString(), action.ToString(), message);
                break;
            }
        }
        public void WriteLog(enumOperator action, string message, enumLog4net logLevel)
        {
            switch (logLevel)
            {
            case enumLog4net.INFO:
                _log.Info(Utils.GetIP(), CurrentUser.Name, Request.Url.ToString(), action.ToString(), message);
                return;

            case enumLog4net.WARN:
                _log.Warn(Utils.GetIP(), CurrentUser.Name, Request.Url.ToString(), action.ToString(), message);
                return;

            default:
                _log.Error(Utils.GetIP(), CurrentUser.Name, Request.Url.ToString(), action.ToString(), message);
                return;
            }
        }
Exemple #9
0
        public override void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;                                               //表示已经处理 不需要mvc框架处理
            var         UserData      = HttpContext.Current.User as MyFormsPrincipal <UserInfo>; //当前操作用户
            UsersExtend curentUser    = null;
            var         routeValueDic = filterContext.RouteData.Values;
            string      actionParameterInfo;

            try
            {
                actionParameterInfo = GetActionParametersInfoStr(filterContext);
            }
            catch
            {
                actionParameterInfo = "参数信息:不能处理参数绑定";
            }
            if (UserData != null)
            {
                curentUser = DepositHelper.GetAsync <UsersExtend>(RedisKeyManager.LoginUserInfo(UserData.UserData.Id.ToString()));
            }
            //如果是ajax请求则返回json格式数据  否则跳转到错误页面
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                JsonResult json = new JsonResult();
                json.Data = new ProcessResult()
                {
                    State = ProcessEnum.Fail, Message = filterContext.Exception.Message
                };
                filterContext.Result = json;
            }
            else
            {
                filterContext.Result = new RedirectResult("/plug/Error/Error404.html");
            }
            log.Error(ClientIP.GetIp(filterContext.RequestContext.HttpContext.ApplicationInstance.Request), curentUser == null ? "未登陆" : curentUser.LoginName, filterContext.HttpContext.Request.UrlReferrer.ToString(), routeValueDic["action"].ToString(), "mvc全局捕获异常", filterContext.Exception, actionParameterInfo);//写入日志
            base.OnException(filterContext);
        }
        public ActionResult Login(Domain.SYS_USER item)
        {
            var json = new JsonHelper()
            {
                Msg = "登录成功", Status = "n"
            };

            try
            {
                //获取表单验证码
                var code = Request.Form["code"];
                if (Session["gif"] != null)
                {
                    //判断用户输入的验证码是否正确
                    if (!string.IsNullOrEmpty(code) && code.ToLower() == Session["gif"].ToString().ToLower())
                    {
                        //调用登录验证接口 返回用户实体类
                        var users = UserManage.UserLogin(item.ACCOUNT.Trim(), item.PASSWORD.Trim());
                        if (users != null)
                        {
                            //是否锁定
                            if (users.ISCANLOGIN)
                            {
                                json.Msg = "用户已锁定,禁止登录,请联系管理员进行解锁";
                                log.Warn(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
                                return(Json(json));
                            }

                            var acconut = this.UserManage.GetAccountByUser(users);

                            //系统访问正常
                            if (acconut.System_Id.Count > 0)
                            {
                                //是否启用单用户登录
                                if (System.Configuration.ConfigurationManager.AppSettings["IsSingleLogin"] == "True")
                                {
                                    var UserOnline = UserOnlineManage.LoadListAll(p => p.FK_UserId == users.ID).FirstOrDefault();
                                    if (UserOnline != null && UserOnline.IsOnline)
                                    {
                                        json.Msg = "当前用户已登录,系统不允许重复登录!登录IP:" + UserOnline.UserIP;
                                        log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "重复登录:" + json.Msg);
                                    }
                                    else
                                    {
                                        //写入Session 当前登录用户
                                        SessionHelper.SetSession("CurrentUser", acconut);

                                        //记录用户信息到Cookies
                                        string cookievalue = "{\"id\":\"" + acconut.Id + "\",\"username\":\"" + acconut.LogName +
                                                             "\",\"password\":\"" + acconut.PassWord + "\",\"ToKen\":\"" +
                                                             Session.SessionID + "\"}";
                                        CookieHelper.SetCookie("cookie_rememberme", new Common.CryptHelper.AESCrypt().Encrypt(cookievalue),
                                                               null);

                                        json.Status = "y";
                                        json.ReUrl  = "/Sys/Home/Index";
                                        log.Info(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
                                    }
                                }
                                else
                                {
                                    //写入Session 当前登录用户
                                    SessionHelper.SetSession("CurrentUser", acconut);

                                    //记录用户信息到Cookies
                                    string cookievalue = "{\"id\":\"" + acconut.Id + "\",\"username\":\"" + acconut.LogName +
                                                         "\",\"password\":\"" + acconut.PassWord + "\",\"ToKen\":\"" +
                                                         Session.SessionID + "\"}";
                                    CookieHelper.SetCookie("cookie_rememberme", new Common.CryptHelper.AESCrypt().Encrypt(cookievalue),
                                                           null);

                                    json.Status = "y";
                                    json.ReUrl  = "/Sys/Home/Index";
                                    log.Info(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
                                }
                            }
                            else
                            {
                                json.Msg = "站点来源不可信,系统拒绝登录";
                                log.Warn(Utils.GetIP(), "其他系统访问者", "", "Login", "其他系统登录失败,原因:系统验证错误,系统拒绝登录");
                            }
                        }
                        else
                        {
                            json.Msg = "用户名或密码不正确";
                            log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
                        }
                    }
                    else
                    {
                        json.Msg = "验证码不正确";
                        log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
                    }
                }
                else
                {
                    json.Msg = "验证码已过期,请刷新验证码";
                    log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
                }
            }
            catch (Exception e)
            {
                json.Msg = e.Message;
                log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
            }
            return(Json(json, JsonRequestBehavior.AllowGet));
        }