예제 #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Thread.CurrentThread.CurrentCulture = CultureHelper.Russian;

            base.OnActionExecuting(filterContext);

            CurrentUser = UserHelper.CurrentUser;

            ProcessUserAgentTag(filterContext);

            if (Request.IsAuthenticated)
            {
                if (CurrentUser == null)
                {
                    Session.Abandon();
                    FormsAuthentication.SignOut();
                    filterContext.Result = new RedirectResult("~/");
                    return;
                }
            }

            if (!filterContext.IsChildAction)
            {
                var fullContext = new FullRequestContext(this);
                FullRequestContext.Current = fullContext;
            }
            DbContext = FullRequestContext.Current.DbContext;

            if (Request.IsAuthenticated && !CurrentUser.IsSwitched)
            {
                // не будем логировать действия системных пользователей
                // а то когда смотришь лог, в самых актуальных записях видишь свои же запросы
                if (!string.Equals(CurrentUser.AccountName, SystemAccountHelper.SystemAccountName, StringComparison.OrdinalIgnoreCase))
                {
                    var uri = filterContext.HttpContext.Request.Url;
                    if (uri != null && !filterContext.IsChildAction && !filterContext.HttpContext.Request.IsAjaxRequest())
                    {
                        var actionName     = filterContext.ActionDescriptor.ActionName;
                        var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                        var baseUrl        = controllerName + "/" + actionName;
                        ConfigDbServicesHelper.GetUserAccountActivityService().Add(CurrentUser.Id, baseUrl);
                    }
                }

                var control = MvcApplication.ComponentControl;

                var message = string.Format(
                    "Пользователь {0} c IP {1}",
                    CurrentUser.Login,
                    FullRequestContext.Current.Ip);

                control
                .CreateComponentEvent("Пользователь на сайте", message)
                .SetImportance(Api.EventImportance.Success)
                .SetJoinInterval(TimeSpan.FromMinutes(Session.Timeout))
                .SetJoinKey(CurrentUser.Login, FullRequestContext.Current.Ip)
                .SetProperty("UserAgent", filterContext.HttpContext.Request.UserAgent)
                .SetProperty("IP", FullRequestContext.Current.Ip)
                .Add();
            }
        }