Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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());
});
like image 653
Bunyamin Aslan Avatar asked Dec 12 '25 06:12

Bunyamin Aslan


1 Answers

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

like image 104
Yinqiu Avatar answered Dec 14 '25 06:12

Yinqiu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!