0
私は、WCFとMembership.CreateUserを使用して新しいユーザーを作成します。ユーザーを作成した後、または作成が失敗した場合、保存しようとすると、MembershipCreteStatusが2回以上返されます。
ユーザーを作成して別のユーザーを作成すると、「ユーザーが正常に作成されました」というステータスメッセージが2回表示されます。あるいは、新しいユーザーを作成しようとする最初の試みが失敗した場合、ユーザー名が既に存在するため、それ以上の試みがあれば、複数の状況メッセージが返されます。方法
tmsClient.CreateNewUserCompleted += new EventHandler<CreateNewUserCompletedEventArgs>(tmsClient_CreateNewUserCompleted);
tmsClient.CreateNewUserAsync(nu.UserName, nu.Password, nu.Email, nu.SecurityQuestion, nu.SecurityAnswer);
へ
私のWCFサービスコード
[OperationContract]
public MembershipCreateStatus CreateNewUser(string userName, string password, string email, string securityQuestion, string securityAnswer)
{
MembershipCreateStatus status = new MembershipCreateStatus();
MembershipUser newUser = Membership.CreateUser(userName, password, email, securityQuestion, securityAnswer, true, out status);
return status;
}
私の呼び出しは、私のイベントは
void tmsClient_CreateNewUserCompleted(object sender, CreateNewUserCompletedEventArgs e)
{
MembershipCreateStatus status = e.Result;
string result = GetErrorMessage(status);
MessageBox.Show(result);
}
そして最後にGetErrorMessageメソッドを完了
public string GetErrorMessage(MembershipCreateStatus status)
{
switch (status)
{
case MembershipCreateStatus.Success:
return "The user was successfully created.";
case MembershipCreateStatus.DuplicateUserName:
return "Username already exists. Please enter a different user name.";
case MembershipCreateStatus.DuplicateEmail:
return "A username for that e-mail address already exists. Please enter a different e-mail address.";
case MembershipCreateStatus.InvalidPassword:
return "The password provided is invalid. Please enter a valid password value.";
case MembershipCreateStatus.InvalidEmail:
return "The e-mail address provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidAnswer:
return "The password retrieval answer provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidQuestion:
return "The password retrieval question provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidUserName:
return "The user name provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.ProviderError:
return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
case MembershipCreateStatus.UserRejected:
return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
default:
return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
}
}
これはなぜ起こっているのですか? のTx
ニール
これはすごくうれしいです - dmusialありがとう – Neill