Bunyamin Aslan
Bunyamin Aslan

Reputation: 263

How to set Secure Flag for.AspNetCore.Antiforgery?

I am using .net core 3.1 on my project. I set Secure flag true for every cookie but I can not set Secure flag for AspNetCore.Antiforgery.

services.AddControllers(options =>
{
    options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});

Upvotes: 17

Views: 10155

Answers (1)

Yinqiu
Yinqiu

Reputation: 7190

You can set secure flag for AspNetCore.Antiforgery like following:

 services.AddAntiforgery(options =>
        {
            options.Cookie.SecurePolicy =CookieSecurePolicy.Always;
        });

Remember to clear the previous cookies first.

Result: enter image description here

Upvotes: 40

Related Questions