When the user refreshes the page, your C# state is gone. To persist data across refreshes in Blazor WASM, you must use browser storage.
Data stays forever (until cleared). Perfect for 'Remember Me' flags, theme preferences, and cached datasets. It survives browser restarts.
Data stays only for the current tab session. Perfect for storing temporary form data or the state of a multi-step wizard. If the user closes the tab, the data is gone.
Use a library like Blazored.LocalStorage. It provides a clean, async .NET API for interacting with the Javascript storage APIs. Always encrypt sensitive data before storing it on the client, as LocalStorage is plain text and viewable by anyone who has access to the computer.
Q: "Can I use LocalStorage in Blazor Server?"
Architect Answer: "YES, but with a warning. You must call it via JS Interop. Be careful about 'Pre-rendering'. During the pre-render phase on the server, the browser storage doesn't exist yet, so your code will fail. Always wrap your storage calls in a check for OnAfterRenderAsync(true) to ensure the browser environment is ready."