Disable .AspNetCore.Antiforgery Cookie

我的未来我决定 提交于 2020-05-13 08:57:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!