Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Add image to identity profile in Blazor on .NET 8

$
0
0

I am using Microsoft Visual Studio Community 2022 (64-bit) v17.14.16. I have followed your code but I am getting error in OnValidSubmitAsync when the function

 private async Task OnValidSubmitAsync() {     var firstName = user.FirstName;     var lastName = user.LastName;     if (Input.FirstName != firstName)     {         user.FirstName = Input.FirstName;         await UserManager.UpdateAsync(user);     }     if (Input.LastName != lastName)     {         user.LastName = Input.LastName;         await UserManager.UpdateAsync(user);     }     if (Input.ProfilePicture != null && Input.ProfilePicture.Length > 0)     {         user.ProfilePicture = Input.ProfilePicture;         await UserManager.UpdateAsync(user);     }     if (Input.PhoneNumber != phoneNumber)     {         var setPhoneResult = await UserManager.SetPhoneNumberAsync(user, Input.PhoneNumber);         if (!setPhoneResult.Succeeded)         {             RedirectManager.RedirectToCurrentPageWithStatus("Error: Failed to set phone number.", HttpContext);         }     }     await SignInManager.RefreshSignInAsync(user);     RedirectManager.RedirectToCurrentPageWithStatus("Your profile has been updated", HttpContext);}

This error in the console:

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]      Unhandled exception in circuit 'yahbi1W7qDkUrcjvWNvKuK3B755old6G346MHD5HLfQ'.      System.InvalidOperationException: Headers are read-only, response has already started.         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowHeadersReadOnlyException()         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_SetCookie(StringValues value)         at Microsoft.AspNetCore.Http.ResponseCookies.Append(String key, String value, CookieOptions options)         at Microsoft.AspNetCore.Authentication.Cookies.ChunkingCookieManager.AppendResponseCookie(HttpContext context, String key, String value, CookieOptions options)         at Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleSignInAsync(ClaimsPrincipal user, AuthenticationProperties properties)         at Microsoft.AspNetCore.Authentication.AuthenticationService.SignInAsync(HttpContext context, String scheme, ClaimsPrincipal principal, AuthenticationProperties properties)         at Microsoft.AspNetCore.Identity.SignInManager`1.SignInWithClaimsAsync(TUser user, AuthenticationProperties authenticationProperties, IEnumerable`1 additionalClaims)         at Microsoft.AspNetCore.Identity.SignInManager`1.RefreshSignInAsync(TUser user)         at BlazorApp1.Components.Account.Pages.Manage.Index.OnValidSubmitAsync() in C:\Users\aamir\source\repos\BlazorApp1\BlazorApp1\Components\Account\Pages\Manage\Index.razor:line 149         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)         at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)dbug: Microsoft.AspNetCore.SignalR.HubConnectionHandler[6]      OnConnectedAsync ending.

I tried to save first name, last name and profile picture in the class ApplicationUser derived from IdentityUser. The data is saving after following the code but getting error message on a function. On page reload from browser the error message disappears and the data is loaded correctly.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>