-
-
Notifications
You must be signed in to change notification settings - Fork 119
Description
I'm using the .NET8 Blazor web app template, with the Identity stuff included.
I would like to set a local storage item when the user logs in, so added a single line to the Login.razor
method that is called when the form is submitted...
public async Task LoginUser() {
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
SignInResult result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
if (result.Succeeded) {
await LocalStorage.SetItemAsStringAsync("Greeting", Input.Salutation);
Logger.LogInformation("User logged in.");
RedirectManager.RedirectTo(ReturnUrl);
} else if (result.RequiresTwoFactor) {
RedirectManager.RedirectTo(
"Account/LoginWith2fa",
new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
} else if (result.IsLockedOut) {
Logger.LogWarning("User account locked out.");
RedirectManager.RedirectTo("Account/Lockout");
} else {
_errorMessage = "Error: Invalid login attempt.";
}
}
In this case, I have added a Salutation
property to the InputModel
, and want to store that in local storage.
However, when this is run, I get an exception....
InvalidOperationException: JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method
OK, so I added the following at the top of the file...
@rendermode @(new InteractiveServerRenderMode(prerender: false))
However, that gives a different exception...
System.InvalidOperationException: Headers are read-only, response has already started
I'm a bit stuck now. Anyone able to explain how I do this?
Thanks