My issue is that I would like to share the ASP.NET identity cookie between .NET Core and .NET
I have the latest version of ASP.NET Identity in both places – the .NET Core is a new login page, the .NET is a legacy app that will be converted to .NET Core in the distant future.
I would like the two apps to share the cookie so if you log out of one, it logs out of the other.
Has anyone any experience of this? Know what settings are needed? Surely its something that has come up somewhere before?
This is my code:
ASP.NET Core (.NET 6) (login page)
services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
options.SlidingExpiration = true;
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.Name = ".MyCookie";
});
ASP.NET 4.8 (legacy app)
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
ExpireTimeSpan = TimeSpan.FromMinutes(10),
SlidingExpiration = true,
CookieSameSite = Microsoft.Owin.SameSiteMode.Strict,
CookieSecure = CookieSecureOption.Always,
CookieName = ".MyCookie"
});
2
Answers
You can check the thread below first, I have double confirmed it is you wanted.
How to share a session values between an ASP.NET and ASP.NET Core application?
You need to follow the steps to modify the code in this repo. You can check the test result.
https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-7.0#share-authentication-cookies-between-aspnet-4x-and-aspnet-core-apps