扩展 Active Directory 成员资格提供程序
我有一个 ASP.NET 网站,它将使用 Active Directory 来存储用户。 要求允许用户使用他们的电子邮件作为用户名。 Active Directory 不允许用户名中出现“@”等字符。 我创建了一个类来扩展 ActiveDirectoryMembershipProvider;它在调用之前将用户名从 ([email protected] 转换为 user_x0040_domain.com )基类函数。 示例:
public override bool ValidateUser(string username, string password)
{
string encodedUsername = this.Encode(username);
return base.ValidateUser(encodedUsername, password);
}
问题是 MembershipUser 中不允许更改用户名。 我如何处理重写返回 MembershipUser 的方法? 像 MembershipUser GetUser(string username, bool userIsOnline)
I have an ASP.NET web site that will use Active Directory to store Users.
There is a requirement to allow users to use their emails as username.
Active directory will not allow characters like "@" in the usernames.
I created a class to extend the ActiveDirectoryMembershipProvider; It converts usernames from ([email protected] to user_x0040_domain.com ) before calling the base class functions.
example:
public override bool ValidateUser(string username, string password)
{
string encodedUsername = this.Encode(username);
return base.ValidateUser(encodedUsername, password);
}
The Problem is that in the MembershipUser does not allow changing the username.
How can I handle overriding the methods that return MembershipUser?
Like MembershipUser GetUser(string username, bool userIsOnline)
我想您可以覆盖 Active Directory 提供程序返回的 MembershipUser,如下所示:
注意:您需要确保覆盖所有返回用户的方法。它还对集合方法有一些性能影响,因为您需要复制集合(如我在示例中所示)。
I suppose you could do this overriding the MembershipUser returned by the Active Directory provider, something like this:
NOTE: you will need to ensure all methods that return a user are overriden. It also has a some performance impact on collection methods, because you'll need to duplicate the collection (as I have shown in the sample).