在布拉佐爾中:我正在創(chuàng)建一個自定義 AuthenticationStateProvider 類,以便我可以使用托管在 mssql 上的自定義用戶數(shù)據(jù)庫。我的自定義類是:public class ServerAuthenticationStateProvider : AuthenticationStateProvider{ string UserId; string Password; public void LoadUser(string _UserId, string _Password) { UserId = _UserId; Password = _Password; } public override async Task<AuthenticationState> GetAuthenticationStateAsync() { var securityService = new SharedServiceLogic.Security(); var userService = new UserService(); var validPassword = await securityService.ValidatePassword(UserId, Password); var authenticated = validPassword == true ? true : false; var identity = authenticated ? new ClaimsIdentity(await userService.GetClaims(UserId), "AuthCheck") : new ClaimsIdentity(); var result = new AuthenticationState(new ClaimsPrincipal(identity)); return result; }}然后我在 Startup.cs 中注冊它: public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddServerSideBlazor(); services.AddSingleton<UserService>(); services.AddAuthorizationCore(); services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>(); }我的 App.razor 是:<CascadingAuthenticationState> <Router AppAssembly="typeof(Startup).Assembly"> <NotFoundContent> <p>Sorry, there's nothing at this address.</p> </NotFoundContent> </Router></CascadingAuthenticationState>現(xiàn)在我想使用 Index.razor 中的服務(wù):@page "/"@using BadgerWatchWeb.Services@inject AuthenticationStateProvider AuthenticationStateProvider<h1>Sup</h1>由于錯誤,我無法運行此代碼。錯誤說AuthenticationStateProvider does not contain a definition of LoadUser。我認(rèn)為該服務(wù)將能夠使用 ServerAuthenticationStateProvider 中的類。難道不是這樣嗎?
未使用自定義授權(quán)服務(wù),即使它已在服務(wù)中聲明
函數(shù)式編程
2023-09-16 20:01:40