For identifying users who accidently closed the browser window – using the Application.ClientId helped to identify their application session. Since a couple of weeks we receive “error reports” from customers that this behaviour doesn’t work anymore. When debugging with Wisej 3.5.6 and Wisej 4.0.3 – using MS Edge, Firefox and Chrome – the outcome was that indeed the Application.ClientId changed when closing and re-opening any browser. What is the cause of this behaviour and how can it be “fixed”?
The Application.ClientId is stored in the browser’s LocalStorage. The reason you’re seeing ClientId changing after closing and reopening the browser is most likely due to recent browser privacy changes.
Modern browsers (Chrome, Edge, Firefox) have been implementing stricter privacy measures, including:
Solutions
1. Use Cookie-Based Storage Instead
You can store your own client identifier in cookies rather than relying solely on Application.ClientId:
// At application start, check for existing client ID in cookies
var existingClientId = Application.Cookies["MyClientId"];
if (string.IsNullOrEmpty(existingClientId))
{
// Generate and store a new client ID
var newClientId = Guid.NewGuid().ToString();
Application.Cookies.Add("MyClientId", newClientId);
}
2. Configure Session Storage to Use LocalStorage
In your Default.json, ensure you have the session storage set to “local”:
{
"sessionStorage": "local"
}
This allows the session to survive browser closure, but may still be affected by browser privacy settings. See https://docs.wisej.com/docs/concepts/configuration for more information
3. Implement User Authentication
The most reliable approach is to implement proper user authentication. When users log in, you can associate their session with their user account in your database, making browser storage irrelevant for session recovery:
// After successful login
Application.Session.UserId = authenticatedUserId;
// Store session info server-side linked to the user
4. Check Browser Settings with Users
Have affected users check their browser settings for:
Hope this helps,
Julie
Please login first to submit.
