我想对下面的代码提供一些反馈。我如何在角色中的FindUsersByName上实现模式匹配,以便不需要完全匹配用户名?
// MembershipProvider.FindUsersByName
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
MembershipUserCollection users = new MembershipUserCollection();
try
{
Profile.MembershipMapper memberMapper = new MembershipMapper();
List<Profile.Membership> recs = (List<Profile.Membership>)memberMapper.GetMembershipsByUsername(_memberUtil.GetApplicationId(), usernameToMatch, pageIndex, pageSize, out totalRecords);
foreach (Profile.Membership rec in recs)
{
users.Add(GetUserFromModel(rec, usernameToMatch));
}
}
catch (Exception ex)
{
Exception e = CheckEventLog(ex, "FindUsersByName");
throw e;
}
return users;
}
答案 0 :(得分:0)
如果您想要模糊匹配,可以使用正则表达式。让输入传递一个RegEx字符串。你不清楚什么应该匹配,什么不应该。