public override void OnActionExecuting(ActionExecutingContext filterContext) { var isCookiePresent = CookieDetectionProvider.IsCookiePresent(filterContext.HttpContext); if (!isCookiePresent && RobotCrawlerProvider.IsRobot(filterContext.HttpContext)) { return; } if (!isCookiePresent && !filterContext.ActionDescriptor.ActionName.Equals("Cookies", StringComparison.CurrentCultureIgnoreCase) && !filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.Equals("Home", StringComparison.CurrentCultureIgnoreCase)) { CookieDetectionProvider.SetCookie(filterContext.HttpContext); var request = filterContext.RequestContext.HttpContext.Request; var returnUrl = request != null && request.Url != null ? request.Url.PathAndQuery : "/"; var helper = new UrlHelper(filterContext.RequestContext); var url = helper.Action("Cookies", "Home", new { ReturnUrl = returnUrl }); filterContext.Result = new RedirectResult(url); return; } if (isCookiePresent) { if (filterContext.ActionDescriptor.ActionName.Equals("Cookies", StringComparison.CurrentCultureIgnoreCase) && filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.Equals("Home", StringComparison.CurrentCultureIgnoreCase)) { var url = filterContext.HttpContext.Request.QueryString.Get("returnUrl"); if (url.IsValidReturnUrl()) { filterContext.Result = new RedirectResult(url); return; } } else { filterContext.Controller.ViewBag.ShowEuCookieDirective = EuCookieDirectiveProvider.ShowEuCookieDirective(filterContext.HttpContext); } } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var isCookiePresent = CookieDetectionProvider.IsCookiePresent(filterContext.HttpContext); if (!isCookiePresent && RobotCrawlerProvider.IsRobot(filterContext.HttpContext)) { return; } if (!isCookiePresent && !IsCookiePage(filterContext)) { CookieDetectionProvider.SetCookie(filterContext.HttpContext); var request = filterContext.RequestContext.HttpContext.Request; var returnUrl = request != null && request.Url != null ? request.Url.PathAndQuery : "/"; var helper = new UrlHelper(filterContext.RequestContext); var url = helper.Action("Cookies", "Home", new { ReturnUrl = returnUrl }); filterContext.Result = new RedirectResult(url); return; } if (isCookiePresent) { if (IsCookiePage(filterContext)) { var url = filterContext.HttpContext.Request.QueryString.Get("returnUrl"); if (url.IsValidReturnUrlIncludingRoot()) { filterContext.Result = new RedirectResult(url); return; } } else if (!IsAuthenticationPage(filterContext)) { filterContext.Controller.ViewBag.ShowEuCookieDirective = EuCookieDirectiveProvider.ShowEuCookieDirective(filterContext.HttpContext); } } base.OnActionExecuting(filterContext); }