Sourabh Dhiman

Sourabh Dhiman

  • 1.4k
  • 592
  • 32.2k

Login web api consume.

Dec 22 2020 7:34 AM
Hello EveryOne i'm new in .net core .How to consume a login web api in .net core
client.BaseAddress = new Uri("http://abc.abc.com/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.PostAsJsonAsync("api/LoginRegister/LoginUser", login).Result;
//var contents = response.Content.ReadAsAsync<AuthToken>().Result;
var contents = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
//HttpContext.Session.SetString("AdminName", contents.);
//HttpContext.Session.SetString("AdminRoleId", Convert.ToString(admindetails.RoleId));
//HttpContext.Session.SetString("AdminId", Convert.ToString(admindetails.UserId));
//HttpContext.Session.SetString("AdminImage", Convert.ToString(admindetails.UserProfilePic));
TempData["msg"] = "Login Successfully";
return RedirectToAction("Dashboard", "Dashboard");
I have use this code but not login.Please   Help me

Answers (2)