Karan Thakkar

Karan Thakkar

  • 1.8k
  • 203
  • 20.5k

Asp.net core method doesn't executes for second request?

Aug 17 2019 7:25 AM
I am using ASP.NET Core Web API and authenticating user with LDAP server within API. I am using the third party directory which Novell Directory. Everything is working as expected. The problem occurs when I send the request to API for the second time that is after logout again login method doesn't execute in API it directly skips and moves towards next statement but if debug the and press F11 on that statement method works fine, but not with F10 or F% or without debugging.
  1. [AllowAnonymous]  
  2. [HttpPost]  
  3. [Route("login")]  
  4. public IActionResult Login([FromBody] User user)  
  5. {  
  6. string errorMsg = string.Empty;  
  7. {  
  8. LdapAuthenticationFacade ldap = new LdapAuthenticationFacade();  
  9. errorMsg = ldap.AuthenticateUser(user.LoginId, user.Password, user.ClientIp);  
  10. if (string.IsNullOrEmpty(errorMsg))  
  11. {  
  12. return Ok();  
  13. }  
  14. }  
  15. errorMsg = "Invalid Login ID or Password!";  
  16. return BadRequest(errorMsg);  
  17. }  
  18. public string AuthenticateUser(string loginId, string password, string clientIp)  
  19. {  
  20. string errorMsg = string.Empty;  
  21. dynamic result = GetConnection(loginId);  
  22. try  
  23. {  
  24. if (result.Count > 0)  
  25. {  
  26. var user = result.next();  
  27. if (user != null)  
  28. {  
  29. _connection.Bind(user.DN, password);  
  30. if (_connection.Bound)  
  31. {  
  32. return errorMsg;  
  33. }  
  34. }  
  35. }  
  36. }  
  37. catch (LdapException ex)  
  38. {  
  39. errorMsg = ex.LdapErrorMessage;  
  40. }  
  41. _connection.Disconnect();  
  42. return errorMsg;  
  43. }  

Brought to you by:

Answers (1)