Im trying to let the user change his email but when i try to update the database i get an exception: Specified method is not supported.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ManageEmail(LocalEmailModel model)
{
//UserProfile u = new UserProfile();
if (ModelState.IsValid)
{
bool TryPasswordNow;
var user = Membership.GetUser(User.Identity.Name);
MembershipUser u = Membership.GetUser(User.Identity.Name);
try
{
TryPasswordNow = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.OldPassword);
}
catch (Exception)
{
TryPasswordNow = false;
}
if (TryPasswordNow == true)
{
user.Email = model.NewEmail;
db.SaveChanges();
u.Email = model.NewEmail;
Membership.UpdateUser(u);
}
return RedirectToAction("Manage", "Account");
}
return RedirectToAction("Manage", "Account");
}
As you can see ive tried both db.savechanges and membership.updateuser. The first goes through but doesnt change the email and the second one gives me a exception. Shouldnt both of these work? Why isnt my change registered? Thanks..