コード例 #1
0
ファイル: BaseController.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 方法执行完毕,添加用户行为
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (User.Claims.Count() > 0)
            {
                string userId = User.Claims.Where(t => t.Type == "ID").FirstOrDefault().Value;
                CurrentUser         = new SUserService().GetUserById(ESCConvert.ConvertToInt(userId));
                ViewBag.CurrentUser = CurrentUser;
            }
            else
            {
                context.Result = RedirectToAction("Index", "Account");
                return;
            }



            //记录行为日志  增删改
            if (context.HttpContext.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase))
            {
                SBehaviorLog log = new SBehaviorLog()
                {
                    HttpMethod = context.HttpContext.Request.Method,
                    ReqDate    = DateTime.Now,
                    ReqIP      = context.HttpContext.Request.Host.Host,
                    ReqUrl     = context.HttpContext.Request.Path.Value,
                    UserId     = CurrentUser.ID,
                    ReqParams  = GetFormData(),
                    UserName   = CurrentUser.UserName
                };
                logService.AddBehaviorLog(log);
            }

            base.OnActionExecuting(context);
        }