solution for .NET 8
define the following class:
internal class UnsafeAccessorClassAntiforgeryOptions
{
[UnsafeAccessor(UnsafeAccessorKind.StaticField, Name = "DefaultCookiePrefix")]
public static extern ref string GetUnsafeStaticFieldDefaultCookiePrefix(AntiforgeryOptions obj);
}
then in Program.cs as the first line:
UnsafeAccessorClassAntiforgeryOptions.GetUnsafeStaticFieldDefaultCookiePrefix(new()) = ".AntiForgery.";
more info about UnsafeAccessorAttribute
at: