2014-04-01 115 views
1

使用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 }); 
} 
+0

你得到一个错误,或代码运行良好,但密码不会改变?此外,请确保用户未被锁定... – harsimranb

+0

请向我们显示错误。 –

+0

对不起,它返回false,没有错误。更新了问题。 – WebDevNewbie

回答

1

原来有人在公司内其他人用同样的DEV数据库备份内部OpenID提供者。在开发这个OpenID提供程序的过程中,数据发生了变化,导致了奇怪的行为。幸运的是,我只是偶然注意到我的一些数据变化,并问了其他群体的一些问题,使我免于浪费更多时间。

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

共享数据库时学到的好教训。感谢那些试图帮助你的人:)