I am trying to consume a Web API from my code behind page and after getting the response from the Web Api, I always lose my Session values.
Dim formatter As New JsonMediaTypeFormatter()
Using client = New HttpClient()
Dim chkValue = HttpContext.Current.Session("UserName") // Has a value here
client.BaseAddress = New Uri(apiAddress)
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
Dim response As HttpResponseMessage = Await client.PostAsync("requestURI", "customObject", "formatter")
If response.IsSuccessStatusCode Then
HttpContext.Current.Session("UserName") // Referenced object has value of nothing
Else
End If
End Using
This is within a method using Async modifier, not sure if that could lead to something like this.