I have an acceptance problem. After setting the Microsoft.AspNet.WebPages.WebData
and the corresponding classes, the system correctly created the tables in the database so that I could implement the code for user registration, password and password confirmation. Well, the idea is to write to WebData and my table normally, but when it runs and debug it works until you get to the WebSecurity.CreateUserAndAccount(model.Email, model.Senha.ToString())
method.
The debug informs that login and password are perfectly, but the error says no add null password. Does anyone have an idea of what's missing?
Thank you in advance. Below is the image that proves the error and the configuration codes.
ConfiguringWebConfig:
<system.web><!--Outrasconfigurações--><membershipdefaultProvider="churrascadaProvider">
<providers>
<add name="churrascadaProvider"
type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
</system.web
<appSettings>
<!-- Outras configurações -->
<add key="loginUrl" value="~/Conta"/>
</appSettings>
Within the Global.asax application start:
WebSecurity.InitializeDatabaseConnection("ChurrascadaContext", "Contas", "IdConta", "Email", true);
Controller code:
// POST: Conta/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(ContaModel model)
{
if (ModelState.IsValid)
{
try
{
WebSecurity.CreateUserAndAccount(model.Email, model.Senha.ToString());
//Buscando o Id da Conta no banco e inserindo no objeto conta
Conta conta = new Conta();
conta.IdConta = contasDAO.BuscaPorEmail(conta.Email).IdConta;
return RedirectToAction("Create", "Usuario", new {idConta = conta.IdConta });
}
catch(MembershipCreateUserException e)
{
ModelState.AddModelError("usuario.invalido", e.Message);
return View("Create", model);
}
}
else
{
return View("Create", model);
}
}