ADAL.Net在使用托管的AD账户时抛出“未知用户类型”异常通常是由于未正确设置ADAL.Net的用户类型所致。以下是一个解决方法的代码示例:
using Microsoft.IdentityModel.Clients.ActiveDirectory;
// 设置ADAL.Net的用户类型为托管的AD账户
UserType userType = UserType.Managed;
AuthenticationContext authenticationContext = new AuthenticationContext(authority, validateAuthority: true);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(resource, clientId, redirectUri, new PlatformParameters(PromptBehavior.Auto, userType)).Result;
// 使用ADAL.Net获取访问令牌
string accessToken = authenticationResult.AccessToken;
在上面的代码示例中,我们首先定义了用户类型为UserType.Managed,然后在使用AuthenticationContext获取访问令牌时,将用户类型参数设置为userType。这样就可以正确地使用托管的AD账户登录并获取访问令牌。
请注意,authority、resource、clientId和redirectUri是需要根据你的具体情况进行设置的参数。此外,还需要确保已经引用了Microsoft.IdentityModel.Clients.ActiveDirectory命名空间。
希望以上代码示例能够帮助你解决“未知用户类型”异常问题。如果问题仍然存在,请检查你的ADAL.Net版本是否正确,并确保已正确设置其他相关参数。