Msgraph Calls only via IIS timing out

Martin Janecki 96 Reputation points

I wrote an API to call MSGraph to retrieve user informations over$count=true&$search= and deliver it to my .Net5.0 webapp.

so far everything was working good till I tried to publish the API and run it on my IIS.

From my IIS it only runs into a timeout: "detail": "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (",

I tried to call MSGraph from the same server which works without any problems over postman and in my development environment.

Authentication for my API is done via the azure portal app-registration with client id and client secret.

like this:

public string MSGraphTokenRequest()
    var client = new RestClient("");
    var request = new RestRequest(Method.POST);
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("content-type", "application/x-www-form-urlencoded");
    request.AddParameter("application/x-www-form-urlencoded", "grant_type="+grant_type+"&client_id="+client_id+"&client_secret="+client_secret+"&scope="+scope, ParameterType.RequestBody);
    IRestResponse response = client.Execute(request);
    return JsonConvert.DeserializeObject<Token>(response.Content).access_token; 

and requesting the information:

public IActionResult GetUserTest(string userPrincipalName)
    var client = new RestClient("$count=true&$search=\"userPrincipalName:" + userPrincipalName + "\"");
    client.Timeout = -1;
    var request = new RestRequest(Method.GET);
    request.AddHeader("authorization", "Bearer " + MSGraphTokenRequest());
    request.AddHeader("ConsistencyLevel", "eventual");
    IRestResponse response = client.ExecuteAsync(request).Result;
    if (((int)response.StatusCode) != 200)
        return Problem(response.ErrorMessage);
        return Json(response.Content);

Maybe somebody could guide me in the right direction I have no further ideas how to solve this. Thanks in advance.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,057 questions
0 comments No comments
{count} votes

Accepted answer
  1. Martin Janecki 96 Reputation points

    So my guess is that the IIS-Server is sending it requests with higher port numbers. So these requests were intercepted by our company firewall which of course I asked my dev-ops beforehand, if with this could be a firewall related problem... So the solution to the problem was to add a firewall rule for

    0 comments No comments

0 additional answers

Sort by: Most helpful