public async Task Invoke(HttpContext context) { if (context.Request.Path == "/consent") { ITrackingConsentFeature consentFeature = context.Features.Get <ITrackingConsentFeature>(); if (!consentFeature.HasConsent) { consentFeature.GrantConsent(); } else { consentFeature.WithdrawConsent(); } await context.Response.WriteAsync(consentFeature.HasConsent? "Consent granted \n" : "Consent withdrawn \n"); } await next(context); }
public async Task <IActionResult> Withdraw() { _consentFeature?.WithdrawConsent(); if (_consentFeature?.CanTrack == false) { var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var currentUser = await _userManager.FindByIdAsync(userId); if (currentUser != null) { currentUser.CanTrack = false; await _userManager.UpdateAsync(currentUser); } _logger.Log(LogLevel.Information, "Tracking consent withdrawn"); return(Ok()); } _logger.Log(LogLevel.Information, "Failed to revoke tracking consent"); return(StatusCode(500)); }