예제 #1
0
        public void OnActionExecuted(ActionExecutedContext context)
        {
            // 2.
            var alerts = _alerter.Alerts();

            if (alerts == null)
            {
                return;
            }

            if (alerts.Count == 0 && _alerts.Count == 0)
            {
                return;
            }

            // Persist alerts for the entire request so they are available
            // for display within OnResultExecutionAsync below
            foreach (var alert in alerts)
            {
                _alerts.Add(alert);
            }

            // Result is not a view, so assume a redirect and assign values to persistence
            if (!(context.Result is ViewResult) && _alerts.Count > 0)
            {
                context.HttpContext.Response.Cookies.Append(
                    CookieName,
                    SerializeAlerts(_alerts),
                    new CookieOptions
                {
                    HttpOnly = true,
                    Path     = _tenantPath
                });
            }
        }