I'm using ASP.Net Core 2.2.
By default, session cookie is stored in a cookie named .AspNetCore.Session
on a specific domain (e.g: mydomain.com
).
In my case I have multiple .net core applications under the domain. mydomain.com/Module1
, mydomain.com/Module2
, etc...
With this scenario, all the applications share the same cookie for their session. The consequence is that an application try to read the session of the other and generate a warning in the logs:
Error unprotecting the session cookie. System.Security.Cryptography.CryptographicException: The key {...} was not found in the key ring.
Although It's just a warning and session seems to working fine on each application, I wanted to know the proper way to handle this situation.
Thx.
SameSite is an IETF draft standard designed to provide some protection against cross-site request forgery (CSRF) attacks. Originally drafted in 2016, the draft standard was updated in 2019.
AspNet. ApplicationCookie - is created when cookie authentication is used in the application. This cookie is created by the server on user request and is stored by the browser.
CookieAuth: CookiePolicyOptions provides programmatic configuration for the CookiePolicyMiddleware. services. Configure<CookiePolicyOptions>(options => { options. HttpOnly = true; ... }); This part is a set up of the Cookie policy in terms of privacy, GDPR(for Europe) and other policies.
A solution that I've found is to change the session cookie name for each application:
In Startup / Configure()
:
app.UseSession(new SessionOptions() { Cookie = new CookieBuilder() {
Name = ".AspNetCore.Session.MyApp1"}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With