Implementing browser storage
The browser has a bunch of different ways of storing data in the web browser. They are handled differently depending on what type we use. Local storage is scoped to the user’s browser window. The data will still be saved if the user reloads the page or even closes the web browser.
The data is also shared across tabs. Session storage is scoped to the Browser tab; if you reload the tab, the data will be saved, but if you close the tab, the data will be lost. SessionsStorage
is, in a way, safer to use because we avoid risks with bugs that may occur due to multiple tabs manipulating the same values in storage.
To be able to access the browser storage, we need to use JavaScript. Luckily, we won’t need to write the code ourselves.
In .NET 5, Microsoft introduced Protected Browser Storage, which uses data protection in ASP.NET Core and is not available in WebAssembly. We can, however, use an open-source library called Blazored.LocalStorage...