使用System.Web.Providers.DefaultMembershipProvider与System.Web.Security.MembershipUser,我试图更改数据库中的用户密码。出于某种原因,无论我做什么,MembershipUser.ChangePassword(old,new)都会返回false而不会出错。MembershipUser.ChangePassword始终返回false
在数据库中,与应用程序名称关联的我的ApplicationID是正确的,并且我的用户在Membership和Users表中都附带了该ApplicationID。当涉及到该点时,用户不为空,所有数据在对象中都是准确的。我在这里完全失去,任何帮助将不胜感激,因为没有其他来源能够帮助我。
EDIT:
User is not locked out, the user is active, and the password is correct. All
password requirements are being fulfilled. This is extremely frustrating since
the MembershipUser.GetUser() finds the user and all of its associated data but
will not change the password.
Additional Steps:
- Tried MembershipUser.UnlockUser() just in case, no luck.
- Tried MembershipUser.ResetPassword() then a change. This fails with the
error message "Value cannot be null" even though it should be able to.
- GetSpecificVerion of the entire solution and working to when it first
broke. Every version worked, including my latest (Yay!), but then it
magically stopped working again a few minutes later, no code changes
were made at all.
Bounty added, looking for any and all possibilities that could lead to a fix...
配置文件:
----
<add name="aspnetdb" connectionString="Application Name=appname;Type System Version=SQL Server 2008;server=***,****;Initial Catalog=aspnetdb;Integrated Security=false;pwd=****;user id=****" providerName="System.Data.SqlClient" />
----
----
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="aspnetdb" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" passwordAttemptWindow="10" applicationName="mysite.com" />
</providers>
</membership>
----
方法:
public ActionResult ChangePassword(ChangePasswordViewModel model)
{
// Indicates whether changing the password was successful or not.
Boolean passwordChanged = false;
if (ModelState.IsValid)
{
// Grab the current user.
MembershipUser user = Membership.GetUser(User.Identity.Name, true);
if (user != null)
{
passwordChanged = user.ChangePassword(model.OldPassword, model.NewPassword);
}
}
return Json(new { Success = passwordChanged });
}
你得到一个错误,或代码运行良好,但密码不会改变?此外,请确保用户未被锁定... – harsimranb
请向我们显示错误。 –
对不起,它返回false,没有错误。更新了问题。 – WebDevNewbie