Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net mvc3应用程序中更改密码似乎失败_C#_Asp.net Mvc 3 - Fatal编程技术网

C# 在asp.net mvc3应用程序中更改密码似乎失败

C# 在asp.net mvc3应用程序中更改密码似乎失败,c#,asp.net-mvc-3,C#,Asp.net Mvc 3,我正在对asp.net mvc 3中更改密码的选项进行编程,我有以下帐户控制器代码: [Authorize] [HttpPost] public ActionResult CambiarContraseña(CambioContraseña model) { if (ModelState.IsValid) { // ChangePassword will throw an exception rather // than return false

我正在对asp.net mvc 3中更改密码的选项进行编程,我有以下帐户控制器代码:

[Authorize]
[HttpPost]
public ActionResult CambiarContraseña(CambioContraseña model)
{
    if (ModelState.IsValid)
    {
        // ChangePassword will throw an exception rather
        // than return false in certain failure scenarios.
        bool cambioContraseñaCorrecto = true;
        try
        {
            MembershipUser usuarioActual = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
            cambioContraseñaCorrecto = usuarioActual.ChangePassword(model.ContraseñaVieja, model.ContraseñaNueva);
        }
        catch (Exception)
        {
            cambioContraseñaCorrecto = false;
        }
        if (cambioContraseñaCorrecto)
        {
            return RedirectToAction("CambioContraseñaCorrecto");
        }
        else
        {
            ModelState.AddModelError("", "La actual contraseña es inválida o la nueva contraseña es incorrecta.");
        }
    }
    // If we got this far, something failed, redisplay form
    return View(model);
}

问题是“CambioContraseñaCorrecto”的布尔变量总是错误的,我不明白为什么。所以每次我测试时,应用程序都会打印ModelStat的消息,而不会更改密码。有什么解决方案吗?

您的会员资格提供商是什么?不太确定,但请查看链接,如果有帮助,请查看,以防您以前没有看到。您的提供商总是返回false,或者您遇到异常并将标志设置为false。顺便说一句,永远不要这样做-如果你得到一个例外,你需要知道例外是什么。