Click here to Skip to main content
15,887,425 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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

{
    "message": "success",
    "status": true,
    "data": {
        "userID": "9595",
        "userName": "ADC Test User",
        "userRole": "Administrator",
        "environment": "PY"
    },
    "statusCode": "0000"
}


I need to return data from login success where message=success as logic below :
 if (response.IsSuccessStatusCode)
            {
IF(message=="success" AND status="true")
{
receive `user id and username and user role and password`
}
}


What I have tried:

I call api from razor page login as below :

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, "https://localhost:44374/api/adcxx/ValidateUser");
            request.Content = content;
            var response = await _httpClient.SendAsync(request);
            if (response.IsSuccessStatusCode)
            {
          

             
            }
}
Posted
Comments
Richard Deeming 30-May-23 4:13am    
IF(message=="success" AND status="true")

That's not valid C#. If you want someone to help you fix your code, then you need to show the actual code you're trying to fix, and explain precisely what the problem is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900