本文整理汇总了C#中System.Web.Security.MembershipUserCollection类的典型用法代码示例。如果您正苦于以下问题:C# MembershipUserCollection类的具体用法?C# MembershipUserCollection怎么用?C# MembershipUserCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MembershipUserCollection类属于System.Web.Security命名空间,在下文中一共展示了MembershipUserCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindUsersByEmail
/// <summary>
/// Returns a collection of membership users for which the e-mail address field contains the specified e-mail address.
/// </summary>
/// <param name="emailToMatch">The e-mail address to search for.</param>
/// <param name="pageIndex">The index of the page of results to return. pageIndex is zero-based.</param>
/// <param name="pageSize">The size of the page of results to return.</param>
/// <param name="totalRecords">The total number of matched users.</param>
/// <returns>
/// A <see cref="T:System.Web.Security.MembershipUserCollection"></see> that contains a page of pageSize<see cref="T:System.Web.Security.MembershipUser"></see> objects beginning at the page specified by pageIndex.
/// </returns>
/// <exception cref="T:System.ArgumentException">emailToMatch is longer than 256 characters.- or -pageIndex is less than zero.- or -pageSize is less than one.- or -pageIndex multiplied by pageSize plus pageSize minus one exceeds <see cref="F:System.Int32.MaxValue"></see>.</exception>
public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
MembershipUserCollection collection = new MembershipUserCollection();
CustomMembershipUser newUser;
foreach (MembershipUser oldUser in base.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords))
{
ProfileBase profile = ProfileBase.Create(oldUser.UserName);
string firstName = (string)profile.GetPropertyValue("FirstName");
string lastName = (string)profile.GetPropertyValue("LastName");
string displayName = (string)profile.GetPropertyValue("DisplayName");
newUser = new CustomMembershipUser(oldUser.ProviderName,
oldUser.UserName,
oldUser.ProviderUserKey,
oldUser.Email,
oldUser.PasswordQuestion,
oldUser.Comment,
oldUser.IsApproved,
oldUser.IsLockedOut,
oldUser.CreationDate,
oldUser.LastLoginDate,
oldUser.LastActivityDate,
oldUser.LastPasswordChangedDate,
oldUser.LastLockoutDate,
displayName,
firstName,
lastName);
collection.Add(newUser);
}
return collection;
}
示例2: Page_PreRender
private void Page_PreRender()
{
MembershipUserCollection allUsers = Membership.GetAllUsers();
MembershipUserCollection filteredUsers = new MembershipUserCollection();
if (UserRoles.SelectedIndex > 0)
{
string[] usersInRole = Roles.GetUsersInRole(UserRoles.SelectedValue);
foreach (MembershipUser user in allUsers)
{
foreach (string userInRole in usersInRole)
{
if (userInRole == user.UserName)
{
filteredUsers.Add(user);
break; // Breaks out of the inner foreach loop to avoid unneeded checking.
}
}
}
}
else
{
filteredUsers = allUsers;
}
Users.DataSource = filteredUsers;
Users.DataBind();
}
示例3: MembershipUser
FindByUserName_passes_partial_username_to_provider_and_converts_returned_collection_to_PagedListOfMembershipUser()
{
//arrange
var users = new[]
{
new MembershipUser("AspNetSqlMembershipProvider", "TEST1", "", "", "", "", true, false, DateTime.Now,
DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now),
new MembershipUser("AspNetSqlMembershipProvider", "TEST2", "", "", "", "", true, false, DateTime.Now,
DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now)
};
var usercollection = new MembershipUserCollection();
var membership = new FakeMembershipProvider_FindByUserName
{
ReturnedUsers = usercollection,
TotalRecords = 123,
PageIndex = -1,
PageSize = -1
};
var service = new AspNetMembershipProviderWrapper(membership);
const int pageNumber = 3;
const int size = 10;
var username = new Random().Next().ToString();
//act
var result = service.FindByUserName(username, pageNumber, size);
//assert
Assert.Equal(pageNumber - 1, membership.PageIndex);
Assert.Equal(size, membership.PageSize);
Assert.Equal(usercollection.Count, result.Count());
foreach (var user in result)
Assert.Contains(user, users);
}
示例4: BindUsers
private void BindUsers(bool reloadAllUsers)
{
if (reloadAllUsers)
allUsers = Membership.GetAllUsers();
MembershipUserCollection users = null;
string searchText = "";
if (!string.IsNullOrEmpty(gvwUsers.Attributes["SearchText"]))
searchText = gvwUsers.Attributes["SearchText"];
bool searchByEmail = false;
if (!string.IsNullOrEmpty(gvwUsers.Attributes["SearchByEmail"]))
searchByEmail = bool.Parse(gvwUsers.Attributes["SearchByEmail"]);
if (searchText.Length > 0)
{
if (searchByEmail)
users = Membership.FindUsersByEmail(searchText);
else
users = Membership.FindUsersByName(searchText);
}
else
{
users = allUsers;
}
gvwUsers.DataSource = users;
gvwUsers.DataBind();
}
示例5: FindUsersByName
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
var res = new MembershipUserCollection();
totalRecords = 0; //not filled
try
{
var ad = new ADAuthenticationHelper(
this.domain, this.contextUsername, this.contextPassword);
var users = ad.FindUsers(usernameToMatch);
int counter = 0;
int startIndex = pageSize * pageIndex;
int endIndex = startIndex + pageSize - 1;
foreach (var user in users)
{
if (counter >= startIndex)
{
MembershipUser u = GetUser(user, true);
res.Add(u);
}
if (endIndex > 0)
{
if (counter >= endIndex) { break; }
}
counter++;
}
}
catch (Exception ex)
{
throw new ProviderException("FindUsersByName() error in " + providerName, ex);
}
return res;
}
示例6: FindAll_passes_paging_info_to_provider_and_converts_returned_collection_to_PagedListOfMembershipUser
public void FindAll_passes_paging_info_to_provider_and_converts_returned_collection_to_PagedListOfMembershipUser()
{
//arrange
var users = new[]
{
new MembershipUser("AspNetSqlMembershipProvider", "TEST1", "", "", "", "", true, false, DateTime.Now,
DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now),
new MembershipUser("AspNetSqlMembershipProvider", "TEST2", "", "", "", "", true, false, DateTime.Now,
DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now)
};
var usercollection = new MembershipUserCollection();
var membership = new FakeMembershipProvider_FindAll
{
ReturnedUsers = usercollection,
TotalRecords = 123,
PageIndex = -1,
PageSize = -1
};
var service = new AspNetMembershipProviderWrapper(membership);
const int index = 3;
const int size = 10;
//act
var result = service.FindAll(index, size);
//assert
Assert.Equal(index, membership.PageIndex);
Assert.Equal(size, membership.PageSize);
Assert.Equal(usercollection.Count, result.Count());
foreach (var user in result)
Assert.Contains(user, users);
}
示例7: Index
public ActionResult Index(string search)
{
MembershipUserCollection users = new MembershipUserCollection();
if (!string.IsNullOrEmpty(search))
users = Membership.FindUsersByName("%" + search + "%");
return View(users);
}
示例8: UserList
public UserList(MembershipUserCollection users, int totalRecords)
{
this.TotalRecords = totalRecords;
foreach(MembershipUser u in users)
{
this.Users.Add(new User(u));
}
}
示例9: GetMembershipUsers
public virtual MembershipUserCollection GetMembershipUsers(string providerName)
{
MembershipUserCollection muc = new MembershipUserCollection();
foreach (User u in Children)
{
muc.Add(u.GetMembershipUser(providerName));
}
return muc;
}
示例10: GetHybridMembershipUserCollection
private MembershipUserCollection GetHybridMembershipUserCollection(MembershipUserCollection membershipUserCollection) {
if(membershipUserCollection == null) {
return null;
}
var hybridMembershipUserCollection = new MembershipUserCollection();
foreach(System.Web.Security.MembershipUser membershipUser in membershipUserCollection) {
hybridMembershipUserCollection.Add(GetHybridMembershipUser(membershipUser));
}
return hybridMembershipUserCollection;
}
示例11: CreateCollection
public virtual MembershipUserCollection CreateCollection(IEnumerable<IEntry> entries) {
var users = new MembershipUserCollection();
foreach(var result in entries) {
var user = Create(result);
if(user != null) {
users.Add(user);
}
}
return users;
}
示例12: GetAllUsers
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
var col = new MembershipUserCollection();
foreach (MembershipUser user in base.GetAllUsers(pageIndex, pageSize, out totalRecords)) {
col.Add(GetUser(user.UserName, false));
}
return col;
}
示例13: ToMembershipUserCollection
public static MembershipUserCollection ToMembershipUserCollection(this IEnumerable<User> users)
{
MembershipUserCollection membershipUsers = new MembershipUserCollection();
foreach (User user in users)
{
membershipUsers.Add(user.ToMembershipUser());
}
return membershipUsers;
}
示例14: Count
public void Count ()
{
MembershipUserCollection muc = new MembershipUserCollection ();
Assert.AreEqual (0, muc.Count, "0");
muc.Add (GetMember ("me"));
Assert.AreEqual (1, muc.Count, "1");
muc.Add (GetMember ("me too"));
Assert.AreEqual (2, muc.Count, "2");
muc.SetReadOnly ();
Assert.AreEqual (2, muc.Count, "2b");
}
示例15: GetAllUsers
public MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
var collection = new MembershipUserCollection();
foreach (User user in _userMgr.GetAllUsers())
{
collection.Add(new COATMemebershipUser(user));
}
totalRecords = collection.Count;
return collection;
}