问题
Is there any way to prevent the .AspNetCore.Antiforgery Cookie from being created in Asp.Net Core 2?
From my understanding services.addmvc internally calls AddAntiforgery and I cannot seem to find any way to prevent this?
The reason why this is important is because I cannot set any cookies before the user gives his consent and the .AspNetCore.Antiforgery cookie is set by default.
回答1:
OK, I found a solution. If you add this line to ConfigureServices in Startup.cs the cookie will never be created: services.AddAntiforgery(options => { options.Cookie.Expiration = TimeSpan.Zero;});
来源:https://stackoverflow.com/questions/50411402/disable-aspnetcore-antiforgery-cookie