Пример #1
0
        public IActionResult Cookies()
        {
            ViewData["Title"] = "Cookies";
            var consentFeature = HttpContext.Features.Get <ITrackingConsentFeature>();

            CookiePreferencesViewModel model = new CookiePreferencesViewModel()
            {
                Analytics = consentFeature.CanTrack
            };

            return(View(model));
        }
Пример #2
0
        public IActionResult Cookies(CookiePreferencesViewModel model)
        {
            ViewData["Title"] = "Cookies";

            var consentFeature = HttpContext.Features.Get <ITrackingConsentFeature>();

            if (model.Analytics)
            {
                consentFeature.GrantConsent();
            }
            else
            {
                consentFeature.WithdrawConsent();
                // Google analytics
                RemoveCookie(CookieNames.GA);
                RemoveCookie(CookieNames.GId);
                RemoveCookie($"{CookieNames.GTag}{_keysConfig.GoogleAnalyticsKey.Replace("-", "_")}");
                // Application insights
                RemoveCookie(CookieNames.AIUser);
                RemoveCookie(CookieNames.AISession);
            }

            return(View(model));
        }