Blazor Server .Net 8 Аутентификация файлов cookie без идентификации ⇐ C#
Blazor Server .Net 8 Аутентификация файлов cookie без идентификации
I was trying to do a custom authentication using Blazor Server in .Net 8 but until now not succeed. I'm new to this Blazor framework and please check my work flow why I keep getting the error. I've read some of the article but things in Blazor are moving so fast and I've tried so many method but still unsuccessful.
P/S: If my question is duplicate feel free to comment for removal.
Thanks in advanced!
My page tree
Program.cs
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(x => { x.LoginPath = "/login"; }); builder.Services.AddAuthorization(); builder.Services.AddCascadingAuthenticationState(); /////////////////////////// app.UseAuthentication(); app.UseAuthorization(); Login.razor
@using Microsoft.AspNetCore.Authentication @using Microsoft.AspNetCore.Authentication.Cookies @using System.Security.Claims @* some razor component *@ @code{ [CascadingParameter] public HttpContext httpcontext { get; set; } = default!; public async Task ClickLogin() { _loginbtnLoading = true; if (!string.IsNullOrEmpty(_ntid) && !string.IsNullOrEmpty(_password)) { await Task.Delay(2000); //I'm using LDAP for checking user signin var loginOK = ILoginServices.CheckLoginStatus(_ntid, _password); if (loginOK.success) { var claims = new List(); claims.Add(new Claim(ClaimTypes.Name, _ntid)); // add more claims var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(claimsIdentity); // Sign in the user await httpcontext.SignInAsync(principal); NavManager.NavigateTo("/home"); } else { Snackbar.Add(loginOK.errorMessage, Severity.Error); } } else { Snackbar.Add("Please key in all the required info", Severity.Error); } _loginbtnLoading = false; } } The error produced was System.InvalidOperationException: Headers are read-only, response has already started.
Источник: https://stackoverflow.com/questions/781 ... t-identity
I was trying to do a custom authentication using Blazor Server in .Net 8 but until now not succeed. I'm new to this Blazor framework and please check my work flow why I keep getting the error. I've read some of the article but things in Blazor are moving so fast and I've tried so many method but still unsuccessful.
P/S: If my question is duplicate feel free to comment for removal.
Thanks in advanced!
My page tree
Program.cs
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(x => { x.LoginPath = "/login"; }); builder.Services.AddAuthorization(); builder.Services.AddCascadingAuthenticationState(); /////////////////////////// app.UseAuthentication(); app.UseAuthorization(); Login.razor
@using Microsoft.AspNetCore.Authentication @using Microsoft.AspNetCore.Authentication.Cookies @using System.Security.Claims @* some razor component *@ @code{ [CascadingParameter] public HttpContext httpcontext { get; set; } = default!; public async Task ClickLogin() { _loginbtnLoading = true; if (!string.IsNullOrEmpty(_ntid) && !string.IsNullOrEmpty(_password)) { await Task.Delay(2000); //I'm using LDAP for checking user signin var loginOK = ILoginServices.CheckLoginStatus(_ntid, _password); if (loginOK.success) { var claims = new List(); claims.Add(new Claim(ClaimTypes.Name, _ntid)); // add more claims var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(claimsIdentity); // Sign in the user await httpcontext.SignInAsync(principal); NavManager.NavigateTo("/home"); } else { Snackbar.Add(loginOK.errorMessage, Severity.Error); } } else { Snackbar.Add("Please key in all the required info", Severity.Error); } _loginbtnLoading = false; } } The error produced was System.InvalidOperationException: Headers are read-only, response has already started.
Источник: https://stackoverflow.com/questions/781 ... t-identity
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение