User135423268 posted
Good Day Everyone
I'm trying to call the WEB API from another site which has authentication/Login page that is using FormsAuthentication, I'm successfully calling the API when I'm typing the url below"
http://localhost:40278/api/mywa/getemployeelist
but when I'm calling either in Ajax/JSON or in the MVC Controller, It always return the WHOLE LOGIN PAGE HTML CODES, below is my code on the controller.
Public Async Function GetEmployees() As Task(Of List(Of tblEmployeesList))
Try
Dim getTblEmployeesList As New List(Of tblEmployeesList)
Using client As New HttpClient
client.BaseAddress = New Uri(BaseUrl)
client.DefaultRequestHeaders.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
Dim res As HttpResponseMessage = Await client.GetAsync("api/mywa/getemployeelist")
If res.IsSuccessStatusCode = True Then
Dim EmployeesResponse = res.Content.ReadAsStringAsync().Result
getTblEmployeesList = JsonConvert.DeserializeObject(Of List(Of tblEmployeesList))(EmployeesResponse)
End If
Return getTblEmployeesList
End Using
Catch ex As Exception
End Try
End Function
when i try to test it, an error occur and inside the res.Content.ReadAsStringAsync().Result is the whole html script of the login page
I don't know why this is occur but if there is someone who encounter this and fix this, kindly teach me masters.
Thanks and Regards