Membership的一些随笔

 Guid CreateUser(string username, string password, string email, string comment, string passwordQuestion, string passwordAnswer, bool isApproved, ProfileData profileData, IList<string> roles, IList<string> permissions, IList<Guid> companies, out MembershipCreateStatus status);

 


membershipApi.CreateUser(this.TextBoxUserName.Text.Trim(), this.TextBoxPassword.Text.Trim(), this.TextBoxEmail.Text, this.TextBoxComment.Text, null, null, true, profile, new[] { BH.Roles.网站用户 }, null, new Guid[] { companyId }, out createStatus);

using (TransactionScope ts = new TransactionScope())
   {
    try
    {
     Guid companyId = membershipApi.CreateCompany(null, this.TextBoxCompanyName.Text, BH.CompanyTypes.网站用户, null, CompanyStatus.Enabled, null, new EntityElement(BH.EntityTypes.注册企业));
     MembershipCreateStatus createStatus;
     GenericProfileData profile = new GenericProfileData()
     {
       Phone = this.TextBoxPhone.Text
     };
     membershipApi.CreateUser(this.TextBoxUserName.Text.Trim(), this.TextBoxPassword.Text.Trim(), this.TextBoxEmail.Text, this.TextBoxComment.Text, null, null, true, profile, new[] { BH.Roles.网站用户 }, null, new Guid[] { companyId }, out createStatus);
     ts.Complete();
    }
    catch (InvalidOperationException exp)
    {
     this.MessagePanel.ShowWarning(exp.Message);
     return;
    }
    catch (Exception exp)
    {
     this.MessagePanel.ShowError(exp);
     Logger.Instance(this).Error(exp);
     return;
    }
   }

 

 

 

 

UserStatus userStatus = (UserStatus)Enum.Parse(typeof(UserStatus), this.RadioButtonByUserStatus.SelectedValue);

   int recordsCount;
   var userElements = MembershipApi.FindUsers(this.TextBoxQueryByAgencyName.Text, null, userTypes.ToArray(), this.TextBoxQueryByUserName.Text, userStatus, pageIndex, this.Pager.PageSize, out recordsCount);
   this.RepeaterUsers.DataSource = userElements;
   this.RepeaterUsers.DataBind();

   this.LabelRecordCount.Text = recordsCount.ToString();
   this.Pager.RecordCount = recordsCount;
   this.Pager.CurrentPageIndex = pageIndex + 1;
   this.Pager.DataBind();

 

 

 

 

 

原文地址:https://www.cnblogs.com/duwamish/p/1342263.html