I have designed a basic application that has 3 roles:
* Admin
* Clerk
* Donor
On startup of the project the user is directed to the Login/Register view. If a user login as an admin he should be redirect to the admin view that has an AdminLayoutPage.cshtml. If a donor login he should be redirected to the Donor view with DonorLayoutPage.cshtml. However I dont get the desired result. I have tried methods in the login controller to validate:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<actionresult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null && User.IsInRole("Admin"))
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}