I have a Blazor (.net 8) page code function that uses Blazored.LocalStorage.ILocalStorageService to set a page cookie. If I execute the SetItemAsStringAsync in a page event, say OnAfterRenderAsync, it works. However, what I want is a "login" button that once triggered sets the cookie - so it calls a function that performs SetItemAsStringAsync - and when I set a breakpoint on that line and step over it, the next line is never executed, and the page is refreshed.
In other words, I want to set the user email address in a local storage cookie when he clicks the "Login" button, not on page load. If I use the set item function in page load, it works - but in a button, it does not.
Here is my code:
private async Task UserLogin(){ var loginresult = Utils.AuthenticateUser(authUser.Email, authUser.Password); var user = await Utils.DataInterface.GetUser(authUser.Email); if (loginresult) { await localStorage.SetItemAsStringAsync("website.login", user.Email); }}The above fails. The user variable is an object returned from an EntityFramework database call.