0

It would be grateful if anyone here know how to use the ASP.NET MVC 5 AccountController with SQL Server 2008 that can help me. All I want to do is to modify this to run or call my stored procedure inside of it so my query for the login will work. Or any the same idea as long as I use my stored procedure will work with this ASP.NET MVC. Sorry for inconvenience I'm a newbie to Visual Studio. Thanks in advance for your help.

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
    if (!ModelState.IsValid)
    {
        return View(model);
    }

    // This doesn't count login failures towards account lockout
    // To enable password failures to trigger account lockout, change to shouldLockout: true
    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);
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jmar
  • 23
  • 1
  • 8

1 Answers1

0

What you probably are looking for here is to replace the signinmanager with your own version. Create a class innheriting from SignInManager, then override PasswordSignInAsync

In this function you should run your SP, then either call

base.SignInAsync(user, isPersistent, shouldLockout); 
return SignInStatus.Success; 

or

return SignInStatus.Failure; 

if it failed.

More complete example: https://codereview.stackexchange.com/questions/90306/authenticating-user-password-against-active-directory-using-asp-net-identity

As for how to execute your SP:

You can call a stored procedure in your DbContext class as follows. this.Database.SqlQuery("storedProcedureName",params);

(source: How to call Stored Procedure in Entity Framework 6 (Code-First)?)

devzero
  • 2,510
  • 4
  • 35
  • 55