禁用.AspNetCore.Antiforgery Cookie [英] Disable .AspNetCore.Antiforgery Cookie
问题描述
有什么方法可以防止在ASP.NET Core 2中创建 .AspNetCore.Antiforgery Cookie吗?
Is there any way to prevent the .AspNetCore.Antiforgery Cookie from being created in Asp.Net Core 2?
据我了解services.addmvc在内部调用AddAntiforgery,我似乎找不到任何方法来防止这种情况?
From my understanding services.addmvc internally calls AddAntiforgery and I cannot seem to find any way to prevent this?
之所以如此重要,是因为在用户给出之前,我无法设置任何cookie他的同意和.AspNetCore.Antiforgery cookie是默认设置的。
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.
推荐答案
好,我找到了解决方案。
如果将此行添加到Startup.cs中的ConfigureServices中,将永远不会创建cookie:
services.AddAntiforgery(options => {options.Cookie.Expiration = TimeSpan.Zero;});
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;});
这篇关于禁用.AspNetCore.Antiforgery Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!