0

我想对下面的代码提供一些反馈。我将如何在角色中对 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;
}
4

1 回答 1

0

如果你想要模糊匹配,你可以使用正则表达式。将输入传递到 RegEx 字符串中。您还不清楚什么应该匹配,什么不应该匹配。

于 2013-06-05T20:58:00.193 回答