Ich entwickle eine Blazor-Serveranwendung an .NET .NET 9. Ich verwende die Standard-Cookie-Authentifizierung und versuche, Authentifizierungsstatusbehandlungen für das Vorkommen zu konfigurieren. Ich habe versucht, die von .NET 8+ empfohlene Service AddAuthenticationStatesSerialization zu verwenden.
Code: Select all
// Correctly called directly on builder.Services
builder.Services.AddAuthenticationStateSerialization();
< /code>
Ich erhalte den folgenden Kompilierfehler: < /p>
Error CS1061: 'IServiceCollection' does not contain a definition for 'AddAuthenticationStateSerialization' and no accessible extension method 'AddAuthenticationStateSerialization' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
Hier ist der relevante Teil meines Programms.CS -Konfiguration:
// Program.cs
// Necessary using directive IS present at the top:
using Microsoft.AspNetCore.Components.Authorization;
// Other standard using directives...
var builder = WebApplication.CreateBuilder(args);
// ... other services (HttpClient, DbContextFactory, Antiforgery, HttpContextAccessor etc.)
// Blazor / interactive components + Auth State Handling
builder.Services
.AddRazorComponents()
.AddInteractiveServerComponents(); // Adds interactive server services
// Trying to add state serialization here:
builder.Services.AddAuthenticationStateSerialization(); //
{
o.LoginPath = "/login";
// ... other cookie options ...
});
builder.Services.AddAuthorization(o => { /* ... policies ... */ });
// ... rest of service registrations ...
var app = builder.Build();
// ... middleware pipeline (UseAuthentication, UseAuthorization, UseAntiforgery etc.) ...
// Map components
app.MapRazorComponents()
.AddInteractiveServerRenderMode(); // Server endpoints enabled
// ... rest of Program.cs ...
app.Run();
< /code>
Was ich ausprobiert habe: < /strong> < /p>
bestätigt, dass die Verwendung von Microsoft.aspnetcore.comPonents.Authorisierung; Rebuild -Lösungszyklen in Visual Studio. Befindet sich diese Methode in einem anderen Namespace in .NET 9 -Voransichten, wird sie möglicherweise entfernt/geändert oder könnte es ein Problem mit meiner SDK -Installation oder -projektreferenzen geben, die diesen Typ -Auflösungsfehler verursachen? Forceload: TRUE), die Zielseite mit [Autorize] würde sich wieder in die Anmeldung umleiten, da die vorgeendete Komponente den Auth -Status nicht sofort erkannte. AddAuthenticationStatesSerialisierung war die empfohlene Korrektur, die ich implementieren wollte, als ich diesen Kompilierfehler drücke.