Blazor Server .Net 8 Аутентификация файлов cookie без идентификацииC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Blazor Server .Net 8 Аутентификация файлов cookie без идентификации

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»