これは MVC 4 インターネット アプリケーションです。Web.config ファイルでロール プロバイダーとロール マネージャーを SimpleRoleProvider と SimpleMembershipProvider に設定しましたが、「"WebSecurity" クラスの他のメソッドを呼び出す前に "WebSecurity.InitializeDatabaseConnection" メソッドを呼び出す必要があります」というメッセージが引き続き表示されます。 Global,asax.cs ファイルで WebSecurity.InitializeDatabaseConnection を初期化しても例外が発生します。私が作成してプログラムで割り当てた Authorize 属性の Roles プロパティが完全に機能するため、これが適切に初期化されたことがわかります。私がやりたいことは、ユーザーのユーザー名を取得し、忘れてログインできない場合にメールで送信することだけです。アドバイスをいただければ幸いです。
[HttpPost]
[CaptchaVerify("Captcha is not valid")]
[AllowAnonymous]
public ActionResult ForgotUserNameOrPassword(UserProfile model, FormCollection collection)
{
if (!ModelState.IsValid)
{
ViewBag.Error = "The Captcha answer is incorrect";
return View();
}
else
{
SimpleMembershipProvider mySMP = new SimpleMembershipProvider();
int outRecs;
dynamic email = new Postal.Email("UserNameEmail");
MembershipUserCollection myUserCol =mySMP.FindUsersByEmail(model.UserEmail, 0, 0, out outRecs);
email.Username = myUserCol;
email.To = model.UserEmail;
email.From = model.UserEmail;
email.Send();
return View("../Account/Login");
}
}