User registration and password

Asked

Viewed 480 times

4

I have an acceptance problem. After configuring 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 you run and debug it works until you get to the method WebSecurity.CreateUserAndAccount(model.Email, model.Senha.ToString()).

debug informs you are login and password perfectly, but the error says not to add null password. Does anyone have any idea what is missing?

Thanks in advance. Below the image that proves the error and the configuration codes.

inserir a descrição da imagem aqui

Configuration of the Webconfig:

<system.web>
    <!-- Outras configurações -->
    <membership defaultProvider="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 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);
        }
    }
  • For you to need to give a Tostring() in your password in the controller, it is what type of variable?

1 answer

1

I found the problem. It turns out that the system was searching for the password of the entity "Accounts", but it was empty because it had configured Microsoft.AspNet.Webpages.Webdata to store the password. Therefore, the solution was to search for Microsoft.AspNet.Webpages.Webdata the password to validate..

  • Ronnam accept your answer so that the question is not open

Browser other questions tagged

You are not signed in. Login or sign up in order to post.