Exception error when authenticating login with null values - Simplemembership - ASPNET MVC

0

I've developed a project in asp.net mvc5 from a course I'm doing, which is accusing the following exception error at the time of authenticating the login menu when I do not enter any data in the form fields and step null parameters:

  

"An exception of type 'System.ArgumentException' occurred in   WebMatrix.WebData.dll but was not handled in user code - Additional   information: Value can not be empty or empty "

I believe the problem is with the simplemembership, because in other forms views when I authenticate with null values, this exception error does not occur, and the login menu controller was configured with simplemenbership. I would like to know how to set up the simplemembership to not give this exception error when authenticating with null values. Below is the screen print and logincontroller code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

namespace Financas.Controllers
{
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Autentica(string login, string senha )
        {
               if (WebSecurity.Login(login, senha))
            {
                return RedirectToAction("Index", "Movimentacao");
            }
               else
            {

                ModelState.AddModelError("Login.Invalido", "Login ou senha incorretos");
                return View("Index");
            }
            }
        public ActionResult Logout()
        {
            WebSecurity.Logout();
            return RedirectToAction("Index");

            

        }
    }
}
    
asked by anonymous 11.08.2016 / 17:00

1 answer

0

Well, as the message says, this method does not accept nulls or empty strings . In this case you would have to validate your values directly this way:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

namespace Financas.Controllers
{
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Autentica(string login, string senha )
        {
             if(String.IsNullOrEmpty(login) || String.IsNullOrEmpty(senha)
            {
                ModelState.AddModelError("Login.PreencherTodosCampos", "Por favor, preencha todos os campos.");
                return View("Index");
            }


             if (WebSecurity.Login(login, senha))
            {
                return RedirectToAction("Index", "Movimentacao");
            }
               else
            {

                ModelState.AddModelError("Login.Invalido", "Login ou senha incorretos");
                return View("Index");
            }
            }
        public ActionResult Logout()
        {
            WebSecurity.Logout();
            return RedirectToAction("Index");



        }
    }
}

I hope I have helped.

Hug.

    
24.09.2016 / 23:33