这是一个 MVC 4 Internet 应用程序。我已经在 Web.config 文件中将 Role Provider 和 Role Manager 设置为 SimpleRoleProvider 和 SimpleMembershipProvider ,但我继续得到“在调用“WebSecurity”类的任何其他方法之前必须调用“WebSecurity.InitializeDatabaseConnection”方法”尽管在 Global,asax.cs 文件中初始化了 WebSecurity.InitializeDatabaseConnection 异常。我知道这已正确初始化,因为我创建并以编程方式分配的授权属性中的角色属性工作完美。我要做的就是检索用户用户名,如果他们忘记并且无法登录,则通过电子邮件将其发送给他们。建议表示赞赏。
[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");
}
}