I am trying to make sure that my users log in
as a elementryUser
.So in Login controller i check the username
and password
,if the authentication be true the user can enter the page the code to handle this is given below :(this part of code is login action )
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
System.Threading.Thread.Sleep(10000);
if (User.IsInRole("ElementryUser"))
{
int UserId = objuserrepository.FindBy(i => i.Email == User.Identity.Name).First().Id;
if (firstIdeaRepository.FindBy(i => i.UserId == UserId).Count() > 0)
{
return RedirectToAction("Index", "FirstIdea");
}
}
else
{
return RedirectToAction("Index", "Dashboard");
}
As you can see if the username
and password
be true the cookie is initialized,in this line if (User.IsInRole("ElementryUser"))
when i want to check my user permission but it doesn't work and it doesn't execute if statement
.so i trace the code and i found that the User.Isauthenticated
returns false
!!!!why?what is the problem?So i put and thread between these two line because i thought maybe the thread could solve the problem.But it doens't workUser.Isauthenticated
returns false
and sometimes returns true
and when it returns true my if statement
works .!!
Best regards