Skip to content

Instantly share code, notes, and snippets.

@patkleef
Created March 13, 2017 19:24
Show Gist options
  • Select an option

  • Save patkleef/f7dbbb8363c6997e00490a158cdcdc48 to your computer and use it in GitHub Desktop.

Select an option

Save patkleef/f7dbbb8363c6997e00490a158cdcdc48 to your computer and use it in GitHub Desktop.
Application Insights Blog - ApplicationInsightsEventTracking.cs
[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:
var dic = new Dictionary<string, string>();
dic.Add("email", model.Email);
_telemetryClient.TrackEvent("InvalidLogin", dic);
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment