I have ASP.Net MVC5 site. There is a login view/page.
For validating user, I have an action in controlller. Now if user credentials are valid, I set a session variable.
Code Snippet
public ActionResult ValidateUser(string userName, string pwd)
{
User dal = new User();
bool flag = dal.Authenciate(userName,pwd);
if(flag)
{
Session['userId'] = userName;
}
else
{
//user invalid
}
return View();
}
Now for Authenticated User, subsequent request the hit will go to WebApi Controller.
I am in need to access the Session['userId'] value in WebApi controller, but WebApi doesn't have anything Session as it stands on the REST principle.
Now my question is,What is the right way to handle this requiment?
WebApi Controller
public IEnumerable<Course> Get()
{
int userId = Convert.ToInt32(Session['userId']);
User dal = new User();
IEnumerable<Course> courses= dal.GetCourses(userId);
return courses;
}