The code below works great in a console application.
When it runs on IIS in a web application it times out on the client.GetAync(URL) line.
Any ideas?
static async Task<byte[]> GetLogo(string URL, string AccessToken)
{
byte[] imageData = null;
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", "Bearer " + AccessToken);
HttpResponseMessage response = await client.GetAsync(URL);
if (response.IsSuccessStatusCode)
{
imageData = await response.Content.ReadAsByteArrayAsync();
}
}
return imageData;
}
Thanks,
2
Answers
Search for "Event Viewer" in Windows, then navigate to the Windows Logs folder, and finally open the Application section. In this page, you can view the logs of IIS errors.
You can also log errors through the Web.config file.
Below, I’m providing you with a sample Web.config file. Note that this Web.config file is based on .NET 8 Also, you need to replace ‘YourAppName’ with the name of your application.
Also, please note that the "logsstdout" folders should exist alongside the Web.Config file, and proper access should be granted to them.
It depends on the URL you are trying to access. If you are trying to access a url that is being served by IIS, then you cant access the fully qualified url without adding the URL to the local host file and set the IP to 192.162.0.1
Also, you are using should be injecting the HttpClient in the constructor, something like:
private readonly HttpClient _httpClient;
then in your method use something like, which is using async: