Error while logging in applications

Asked

Viewed 135 times

2

Well, here’s the scenario:

Have 2 applications ASP.NET MVC on the same project, which are using a Dominio in common. I’ll call it MVC1 and MVC2 to get better at exemplification.

I installed the Identity, EntityFramework in the dominio, and ALMOST everything up until then seems to work normally.

In the MVC1thus normally, and if access the system of MVC2 shows me that I am logged in. I can log out among other features. What makes me think that everything is OK.

Now come on...

The only problem I had was logging into the project MVC2. Return me the error:

Server Error in Application/'. Object reference not defined for an instance of an object. Description: An exception has occurred without processing during the execution of the current web request. Examine the stack tracking for more information about the error and where originated in the code.

Exception Details: System.Nullreferenceexception: Reference of object not defined for an object instance.

Error of Origin:

Line 74: // This doesn’t Count login failures Towards Account lockout Line 75: // To enable password failures to Trigger Account lockout, change to shouldLockout: true

Line 76:var result = await Signinmanager.Passwordsigninasync(model. Email, model. Password, model.Rememberme, shouldLockout: false);

Line 77:
switch (result) Line 78:

Code of controller:

 [HttpPost]
 [AllowAnonymous]
 [ValidateAntiForgeryToken]
 public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
   {
        if (!ModelState.IsValid)
        {
            return View(model);
        }
        var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
        }
    }

However, Threshing, put a BreakPoint on line 76 of controller which is the one that generates the error, the fields required for the login are filled

inserir a descrição da imagem aqui

And I saw that logging through the MVC1(which soon usually without the error) it does not enter this method of controller. Already the MVC2 enters and returns me the error quoted above.

How do I solve this problem ?

  • How are you model, model.Email, model.Password and model.RememberMe?

  • Yes. I inserted an image. fields arrive filled.

1 answer

2


Probably missed the dependency injection. Check in your file Startup.Auth.cs if SignInManager is being instantiated correctly:

app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

Browser other questions tagged

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