I am trying to fetch data from database by using EFCore in my asp.net core mvc application, but application crashes, when repository try to return data to controller.
Tools I am using Vs2017, MSSQL2017, Asp.net Core 2.2, EFCore2.2. I have made a repository which authenticate user from database. When I try to authenticate user through repository by sending username and password through controller, so application crashes.
Even though I can see while debugging that user is authenticated and repository fetching that user from database. But when repository try to return user to controller, so application crashes. It does not generate any kind Exception, but crashes as soon as repository try to return user.
But I can see some information in the output windows of Vs2017, which is as follows
"iisexpress.exe' has exited with code -1073741819 (0xc0000005) 'Access violation"
Controller Code
public class LoginController : AppController { private readonly IUserRepository _userRepository;
public LoginController(IUserRepository userRepository)
{
_userRepository = userRepository;
}
[HttpGet]
public IActionResult Login()
{
return View(new LoginViewModel());
}
[HttpPost]
public IActionResult Login(LoginViewModel loginViewModel)
{
loginViewModel.Password = EncryptionLibrary.EncryptText(loginViewModel.Password);
var user = _userRepository.FindUser(loginViewModel.Username, loginViewModel.Password);
if ( user!= null)
{
this.CurrentSaleState.Login.Id = user.Id;
return RedirectToAction("Create", "RegisterCompany");
}
return null;
}
}
Repository Code
public UserModel FindUser(string userName, string password) {
using (IRepositoryContext context = _repositoryFactory.CreateContext())
{
var user = context.Set<User>().FirstOrDefault(u => u.Username == userName && u.Password == password);
var userModel = _modelMapper.Map<User, UserModel>(user);
return userModel;
}
}
I expect that after authenticating user should move to another page.
I'm probably too late to the party but just for whoever wanders here.
I see you're using a mapper.
In my case this exact situation was caused by a StackOverflowException due to erroneous mapping.
User contributions licensed under CC BY-SA 3.0