How do you persist small pieces of state in the browser using Protected Browser Storage or local/session storage?

Last updated 5 July 2026

  • On Blazor Server, ProtectedLocalStorage/ProtectedSessionStorage encrypt values via Data Protection (SetAsync, GetAsync<T>, DeleteAsync). Not available in pure WASM because keys live on the server.

  • Otherwise use JS interop or Blazored.LocalStorage (plain text, user-editable). Local persists across restarts, while session clears on tab close.

  • JS interop can't run during prerendering, so read storage in OnAfterRenderAsync. Best for small, non-critical data like theme or preferences.

  • https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management/?view=aspnetcore-10.0
  • https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management/protected-browser-storage?view=aspnetcore-10.0
  • https://www.telerik.com/blogs/blazor-basics-accessing-browser-storage-blazor-web-applications
  • https://www.syncfusion.com/blogs/post/master-state-management-in-blazor
  • https://medium.com/@kxmliebl/using-session-and-localstorage-in-blazor-and-maui-b01fbb41d14c
  • https://medium.com/@kxmliebl/useful-things-about-blazor-i-wish-i-knew-at-the-start-3666370109be
  • https://dev.to/rasheedmozaffar/how-to-work-with-the-browsers-local-storage-in-blazor-58kc
All Blazor interview questions