I am creating to login page in ASP.NET Core MVC and API. I fetched data
{
"UserId": 4,
"userName": "admin",
"EmailId": "admin@gmail.com",
"Password": "123",
"Role": "admin",
"Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjQiLCJyb2xlIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3ZlcnNpb24iOiJWMy4xIiwibmJmIjoxNjUzODA2NTE4LCJleHAiOjE2NTM5NzkzMTgsImlhdCI6MTY1MzgwNjUxOH0.ogp1MHNrKPvX7P2-nqbHJewOlgS0sSUNcKwADhOeIFc",
"Mobile": null,
"Address": null,
"created_at": "0001-01-01T00:00:00",
"updated_at": "0001-01-01T00:00:00"
}
[HttpPost]
public ActionResult Index(Login model)
{
HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Users", model).Result;
IEnumerable<Login> error = null;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync( ).Result;
// Session["TokenNumber"] = data;
}
else
{
error = Enumerable.Empty<Login>();
ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
}
return View(model);
}
It displays all the data. But I need to fetch only Token
value from that data - not all values.
How to read only the token? It should be stored in session.