且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在ASP.NET的Web API,基于角色的授权 - 如何设置的主要角色?

更新时间:2023-02-15 13:35:25

我发现了AddBasicAutentication方法实际上有一个重载,接受委托提供的角色。这正是我一直在寻找。所以,现在的呼叫AddBasicAuthentication看起来像这样,一切就像一个魅力:

I found out that the AddBasicAutentication method actually has an overload that takes a delegate for providing the roles. This is exactly what I was looking for. So now the call to AddBasicAuthentication looks like this, and everything works like a charm:

authenticationConfiguration.AddBasicAuthentication((userName, password) => accountService.Authenticate(userName, password), (username) => accountService.GetRoles(username));