1

使用 System.Web.Providers.DefaultMembershipProvider 和 System.Web.Security.MembershipUser,我试图更改数据库中的用户密码。出于某种原因,无论我做什么, MembershipUser.ChangePassword(old, new) 都会返回 false 且没有错误。

在数据库中,与应用程序名称关联的 ApplicationID 是正确的,并且我的用户在 Memberships 和 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 });
}
4

1 回答 1

1

结果公司内部的其他人正在使用相同的 DEV 数据库来支持内部 OpenID 提供程序。在此 OpenID 提供程序的开发过程中,数据发生了变化,导致了奇怪的行为。谢天谢地,我刚好注意到我身上的一些数据变化,并向其他小组提出了一些问题,让我不再浪费时间。

我能够检索用户但没有更改该用户的密码仍然很奇怪。最后,清理两个项目之间的沟通似乎已经解决了这个问题。

共享数据库时在这里学到了很好的一课。感谢那些试图提供帮助的人:)

于 2014-04-03T21:20:02.760 回答