Hi,
Same site cookie attribute set vb.net
Hi,
Same site cookie attribute set vb.net
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sandhiya PriyaPosted Oct 23, 2025, 4:09 AM
you’re asking how to set a SameSite cookie attribute in VB.NET (ASP.NET).
Let’s go step-by-step
What is the SameSite Cookie Attribute?
The
SameSiteattribute controls how cookies are sent with cross-site requests to improve security and prevent CSRF attacks.Possible values:
None→ cookie is sent in all requests (must also haveSecure=Truefor HTTPS)Lax→ cookie sent only on top-level GETs (default for most browsers)Strict→ cookie sent only for same-site requestsHow to Set
SameSiteAttribute in VB.NETOption 1: Set it directly when creating a cookie
Option 2: Set globally in
web.config(for all cookies)You can enforce
SameSitebehavior in your Web.config:Option 3: Fix cookies generated by
FormsAuthenticationIf you’re using ASP.NET Forms Authentication, set SameSite for the auth cookie in
Global.asax:Option 4: Modify cookies dynamically (for older .NET versions)
If your .NET Framework version doesn’t support
.SameSiteproperty (e.g., before 4.7.2),you can append the attribute manually:
Recommended Settings (for SSO apps)
If your app uses Single Sign-On (SSO) or any cross-domain login, use:
Otherwise, for a normal internal app (no external redirect), use:
Quick Example (Full VB.NET Code)
Jayraj ChhayaPosted Sep 23, 2025, 9:59 AM
In VB.NET (ASP.NET), you can set the
SameSiteattribute of a cookie using theHttpCookieclass orResponse.Cookiesdepending on whether you are using .NET Framework or .NET Core/ASP.NET Core. Here's a concise guide:ASP.NET (.NET Framework)
Notes:
SameSiteMode.Strict→ Cookie sent only for same-site requests.SameSiteMode.Lax→ Cookie sent for top-level navigation GET requests.SameSiteMode.None→ Cookie sent in all contexts (requiresSecure = True).If
SameSite=None, you must set Secure = True for modern browsers.For cross-site scenarios (like SSO or third-party login),
SameSite=Noneis needed.