public ActionResult Register(RegisterModel RegisterModel, string returnUrl)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] Password = encoding.GetBytes(RegisterModel.Password);
var EncryptedPass = MembershipProvider.EncryptPassword(Password);
Membership.CreateUser(RegisterModel.UserName, RegisterModel.Password, RegisterModel.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(RegisterModel.UserName, false /* createPersistentCookie */);
return Redirect(returnUrl ?? Url.Action("Index", "Education"));
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(RegisterModel);
}
尝试在使用 EncryptPassword 方法将密码存储到数据库之前对其进行加密,然后使用 MembershipProvider.DecryptPassword 方法对其进行 Dycrypt,但收到“由于其保护级别而无法访问”错误警告。