Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check logged in user is Active user or Not in aspnet identity?

Tags:

asp.net-mvc

I'm using asp.net Identity and I have added an "Active" property to my ApplicationUser.

If I set the Active property to false, the user should not be able to sign in even if the username and passwordis correct.

Ho to achieve this? Can anyone point me in the right direction?

like image 299
Rajesh Shetty Avatar asked Oct 14 '25 21:10

Rajesh Shetty


1 Answers

In AccountController.cs update Login Method in case of success for result try this

 var user = db.AspNetUsers.FirstOrDefault(s => s.Email == model.Email);
 if(user.Active == false)
 {
 AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
    ModelState.AddModelError("", "Invalid login attempt.");
    return View(model);
 }
 else 
 {
    return RedirectToLocal(returnUrl);
 }
like image 119
Saqib A. Azhar Avatar answered Oct 17 '25 11:10

Saqib A. Azhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!