I have the following session config in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => false;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
// Set a short timeout for easy testing.
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
// Make the session cookie essential
options.Cookie.IsEssential = true;
});
}
Everything works fine and the session keeps it Session Id and data. I'm putting some booking info there. Then I redirect a user to payment page. After successful payment the user is redirected back to my site via POST to PaymentController Success action.
Obviously, this POST request from payment platform doesn't contain session cookies, so I just do RedirectToAction("ContinueBooking","Payment") inside PaymentController Success action.
After redirect to action - the browser sends session cookies but the session seems to be lost at this time and a new session Id assigned, all data is lost. Is there any way to prevent this ? Or should I just use database to store data between redirects in my case (i can bypass some parameters through payment terminal)?
If both apps are on same server then both will be same cookie and first cookie will be overwritten by the payment app's session cookie. To avoid this customize the cookie name:
services.AddSession(opt =>
{
opt.Cookie.Name = "MySessionCookie";
});
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