1

Microsoft provided here a prompt description how to use this middleware but it has no mention of what the middleware exactly does. What is good for/what does it exactly do?

The code for initialising the middleware in startup.cs is:

app.UseCookiePolicy(cookiePolicyOptions);
Munchkin
  • 857
  • 5
  • 24
  • 51
  • 1
    You can use it for global cookie config. For example setting `Secured` to `true` on all cookies or based on some logic – Artur Sep 07 '21 at 13:28
  • Also checks for cookie consent if needed. – juunas Sep 07 '21 at 13:29
  • @Artur so it checks whether Secure is true on cookies with one of its options? – Munchkin Sep 07 '21 at 13:30
  • @juunas can you elaborate? – Munchkin Sep 07 '21 at 13:30
  • This is a good example https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/ – Artur Sep 07 '21 at 13:31
  • 1
    You can also check the middleware source code here: https://github.com/dotnet/aspnetcore/blob/e687ea05a6dc8185b0ed0bf95f7a618f80d4a3f0/src/Security/CookiePolicy/src/CookiePolicyMiddleware.cs – juunas Sep 07 '21 at 13:35
  • 1
    You can refer to the offcical [doc](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-5.0#cookie-policy-middleware) about cookie authentication. – Yiyi You Sep 08 '21 at 02:12

0 Answers0