services.AddMvc().AddRazorPagesOptions(options => { options.Conventions.AllowAnonymousToPage("/Index"); options.Conventions.AllowAnonymousToPage("/Privacy"); options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute()); });
{ "CookieSettings": { "IsEssential": true, "Name": ".AspNetCore.ConsentCookie", "Expiration": "12:00:00", "Path": "/", "SecurePolicy": "Always", "HttpOnly": true } }
public void OnPageHandlerSelected(PageHandlerSelectedContext context) { var requestCookie = context.HttpContext.Request.Cookies[".AspNetCore.ConsentCookie"]; context.HandlerInstance = requestCookie != null && requestCookie.Contains("gdpr-applies") ? new GdprAgreementFormModel(context.HandlerInstance as GdprAgreementFormModel) : context.HandlerInstance; }
这样做可以确保在Asp.net core中ITrackingConsentFeature与cookie能够正常工作。