Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read data response body after success login razor page ?

Status
Not open for further replies.

AhmedAzizBarbary

Programmer
May 13, 2023
2
EG
I work on asp.net razor page Login user name and password . I call Web API validate user

name and password . my issue I face it I can't receive data returned after login success

JSON data returned from web API after success login username and password

Code:
{
    "message": "success",
    "status": true,
    "data": {
        "userID": "9595",
        "userName": "ADC Test User",
        "userRole": "Administrator",
        "environment": "PY"
    },
    "statusCode": "0000"
}
I call api from razor page login as below :

Code:
public async Task OnPost()
{

           
            UserLoginViewModel loginview = new UserLoginViewModel();
            loginview.UserID = User.UserName;
            loginview.Password = User.vPassword;
            var json = JsonSerializer.Serialize(loginview);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "[URL unfurl="true"]https://localhost:44374/api/adcxx/ValidateUser");[/URL]
            request.Content = content;
            var response = await _httpClient.SendAsync(request);
            if (response.IsSuccessStatusCode)
            {
          

             
            }
}
I need to return data from login success where message=success as logic below :

Code:
 if (response.IsSuccessStatusCode)
            {
IF(message=="success" AND status="true")
{
receive `user id and username and user role and password`
}
}
image below explain what i need to do exactly

image show data I need to receive



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top