public async Task <ActionResult> userlogin(UserData a) { List <UserData> users = new List <UserData>(); HttpClient client = _api.Initaluser(); HttpResponseMessage res = await client.GetAsync("api/User"); if (res.IsSuccessStatusCode) { var results = res.Content.ReadAsStringAsync().Result; users = JsonConvert.DeserializeObject <List <UserData> >(results); } foreach (var item in users) { if (item.Email == a.Email && item.Password == a.Password) { HttpClient clientt = _api.Initalauthorization(); var contentType = new MediaTypeWithQualityHeaderValue ("application/json"); clientt.DefaultRequestHeaders.Accept.Add(contentType); UserData userModel = new UserData(); userModel.Id = 1; userModel.UserName = "******"; userModel.Password = "******"; string stringData = JsonConvert.SerializeObject(userModel); var contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage postTask = clientt.PostAsync ("/api/Account", contentData).Result; // HttpResponseMessage postTask= await client.GetAsync("api/Account"); string stringJWT = postTask.Content.ReadAsStringAsync().Result; JWT jwt = JsonConvert.DeserializeObject <JWT>(stringJWT); HttpContext.Session.SetString("token", jwt.Token); /* if (!result.IsSuccessStatusCode) * { * return RedirectToAction("login"); * } * string apiResponse1 =await result.Content.ReadAsStringAsync(); * // JWT jwt= JsonConvert.DeserializeObject<JWT>(apiResponse1); */ TempData["username"] = item.UserName.ToString(); TempData.Keep(); return(RedirectToAction("BookNow")); } else { ViewBag.msg = "Invalid username or password"; } } return(View()); }