Membership.CreateUserを使用してクライアントの連絡先を作成していますが、連絡先が作成されるたびに生成されたパスワードを提供したいと思います。制作チームは、新しいクライアントの連絡先のアカウントを設定します。
私が遭遇している問題は、一般的なパスワードを渡すと、メソッドが失敗することです。モデルを介して自分のパスワードを入力すると、正常に機能します。
回避策またはより良い方法を探しています。
よろしくお願いします!
コードの例を次に示します。
[HttpPost]
public ActionResult RegisterClientContact(RegisterClientContactViewModel model)
{
if (ModelState.IsValid)
{
//Create Generic password - First initial Last initial 1234
string genericPassword = model.FirstName.Substring(0, 1).ToLower() + model.LastName.Substring(0, 1).ToLower() + "1234";
//Attempt to register the Client Contact
MembershipCreateStatus createStatus;
Membership.CreateUser(model.Email, genericPassword, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
Roles.AddUserToRole(model.Email, "Client");
FormsAuthentication.SetAuthCookie(model.Email, false /*create persistent cookie*/);
Person person = new Person();
person.FirstName = model.FirstName;
person.LastName = model.LastName;
person.Email = model.Email;
person.Phone = model.Phone;
person.Active = true;
db.Persons.Add(person);
db.SaveChanges();
ClientContact clientPerson = new ClientContact();
clientPerson.ClientPersonId = person.Id;
clientPerson.Title = model.Title;
clientPerson.ClientId = model.ClientId;
db.ClientPersons.Add(clientPerson);
db.SaveChanges();
return RedirectToAction("Index", "ClientContact");
}
}
return View("An Error has occured");
}
ちなみに、この記事を考えると、自分のパスワードを渡すことができるはずです。