1
I am getting the following error while trying to change a user’s role :
Server Error in Application '/'.
UserId não encontrada. Descrição: Ocorreu uma exceção sem tratamento durante a execução da atual solicitação da Web. Examine o rastreamento de pilha para
get more information about the error and where it originated in the code.
Detalhes da Exceção: System.InvalidOperationException: UserId não encontrada. Erro de Origem: Linha 91: else Linha 92: { Linha 93: await UserManager.AddToRoleAsync(aspnetuser.Id, "Ong"); Linha 94: return RedirectToAction("Index", "Home"); Linha 95: }
He says userid cannot be found but the userid he receives by parameter is valid (I checked and the same was in db), I do not know if where is my error, I am doing something wrong ? follows below the method used for this :
[HttpGet]
public async Task<ActionResult> AprovarAsync(string Id)
{
IdentityRole aspnetuser = new IdentityRole();
if (Id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
else
{
await UserManager.AddToRoleAsync(aspnetuser.Id, "Ong");
return RedirectToAction("Index", "Home");
}
}
I’ve tried this too :
[HttpGet]
public async Task<ActionResult> AprovarAsync(string Id)
{
var user = new ApplicationUser{ Id = Id };
if (Id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
else
{
await UserManager.AddToRoleAsync(user.Id, "Ong");
return RedirectToAction("Index", "Home");
}
}
But the mistake was another :
Server Error in Application '/'.
Validation failed for one or more entities. See 'Entityvalidationerrors' Property for more Details.
Description: An untreated exception occurred during the execution of current web request. Examine stack tracking to get more information about the error and where it originated in the code.
Details of the Exception: System.Data.Entity.Validation.Dbentityvalidationexception: Validation failed for one or more entities. See 'Entityvalidationerrors' Property for more Details.
I would like to know where I am missing in the construction of this method.