Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Asp.Net Core

Asp.Net Core: Fix a Cookie Policy Blocking a Cross-Site Redirect

- 27.11.26 - ErcanOPAK

⚙️ Asp.Net Core: Fix a Cookie Policy Blocking a Cross-Site Redirect

Setting a cookie’s SameSite policy to Strict is the safest default for most authentication cookies, but it also means the cookie is withheld on the very first request after a user arrives via an external link or a redirect from a third-party identity provider — exactly the flow an OAuth or SSO login depends on. The sign-in can complete successfully on the provider’s side and still land the user back at the app logged out, because the session cookie set moments earlier wasn’t sent along with that first cross-site navigation.

🔎 The Problem

services.ConfigureApplicationCookie(options => {
    options.Cookie.SameSite = SameSiteMode.Strict;
});
// External IdP redirects back via 302 to /signin-oidc
// Browser treats this as a cross-site navigation ->
// the auth cookie just set is withheld on the NEXT request
// User ends up on the home page, still unauthenticated

✅ Fix: Scope SameSite to the Actual Flow That Needs It

  • Use SameSiteMode.Lax for the primary authentication cookie when any part of login happens via a top-level cross-site redirect (OAuth, SAML, OIDC) — Lax still blocks the cookie on cross-site subrequests like images or iframes, while allowing it on full-page navigations.
  • Reserve SameSiteMode.Strict for cookies that genuinely never need to survive an external redirect, such as an anti-CSRF token tied to forms submitted only from within the same site.
  • Test the full external-IdP round trip in an actual browser, not just Postman or a same-site dev environment — SameSite enforcement only manifests on a genuine cross-origin redirect, which local testing against localhost can easily fail to reproduce.

🚨 Why This Is Dangerous

  • An intermittent ‘login succeeded but I’m logged out’ report that only happens for users coming through SSO, and never for users who log in directly, can go undiagnosed for a long time if nobody thinks to check the cookie’s SameSite setting specifically against the redirect flow.

SameSite=Strict protects a cookie from everyone — including the identity provider you just asked to redirect the user back to you.

— Backend Architect

Related posts:

.NET Core: Implement Built-in Health Checks for Microservices

.NET Core: Implement Built-in Health Checks for Microservices

Clean Dependency Injection — Lifetimes That Every Dev Must Master

Clean Dependency Injection — Lifetimes That Every Dev Must Master

.NET Core: Custom Middleware for Global Exception Handling

.NET Core: Custom Middleware for Global Exception Handling

Views: 5
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Visual Studio: Fix Solution Explorer Ignoring Linked Folder Files
Photoshop: Fix Export As Ignoring a Custom Color Profile on PNG

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com