我想您可以覆盖 Active Directory 提供程序返回的 MembershipUser,如下所示:
public class MyActiveDirectoryMembershipProvider : ActiveDirectoryMembershipProvider
{
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
ActiveDirectoryMembershipUser user = (ActiveDirectoryMembershipUser)base.GetUser(providerUserKey, userIsOnline);
if (user == null)
return null;
return new MyActiveDirectoryMembershipUser(user);
}
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
MembershipUserCollection newColl = new MembershipUserCollection();
foreach (ActiveDirectoryMembershipUser user in base.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords))
{
newColl.Add(new MyActiveDirectoryMembershipUser(user));
}
return newColl;
}
// TODO: check other methods to override
}
public class MyActiveDirectoryMembershipUser : ActiveDirectoryMembershipUser
{
private string _userName;
public override string UserName
{
get
{
return _userName;
}
}
public MyActiveDirectoryMembershipUser(ActiveDirectoryMembershipUser user)
{
// TODO: do your decoding stuff here
_userName = MyDecode(user.Email);
}
}
注意:您需要确保所有返回用户的方法都被覆盖。它还对收集方法有一些性能影响,因为您需要复制收集(如我在示例中所示)。