Account folder in project and Register.cs modelProgram.cs codeThis is the user registration controller code on the site that returns the registration view, but when it runs and clicks on the registration, I get a 404 error. Even the registration page follows _Layout.
public class AccountController : Controller
{
//Dependency Injection
private readonly checkRegisterUser _checkRegisterUser;
public AccountController(checkRegisterUser checkRegisterUser)
{
checkRegisterUser = _checkRegisterUser;
}
[HttpPost]
public IActionResult Register(UA_ViewModel register)
{
if (!ModelState.IsValid)
{
return View("Register", register);
}
if(_checkRegisterUser.isExistUserEmail(register.userEmail.ToLower()))
{
ModelState.AddModelError(key:"userEmail", errorMessage:"این ایمیل قبلا ثبت شده است");
return View("Register", register);
}
UsersAccounts user = new UsersAccounts()
{
userName = register.userName,
userEmail = register.userEmail,
userPassword = register.userPassword
};
_checkRegisterUser.addUser(user);
return View("Register", register);
}
}
I tried to solve the error by giving [Route()] attribute and writing Constructor but no change was made.
[AllowAnonymous]on the action method ?