Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET Web API MessageHandler Timing Out
    primarykey
    data
    text
    <p>This question arose when working with the <a href="https://github.com/thinktecture/Thinktecture.IdentityModel.40" rel="nofollow">Thinktecture.IdentityModel.40 library</a> (which is used for authentication in .NET's Web API), however it seems to apply more generally to MessageHandlers / DelegateHandlers. The SendAsync(..) function of the AuthenticationHandler class modifies the Web API's response using a ContinueWith(..) call:</p> <pre><code>return base.SendAsync(request, cancellationToken).ContinueWith( (task) =&gt; { var response = task.Result; if (response.StatusCode == HttpStatusCode.Unauthorized) { SetAuthenticateHeader(response); } return response; } ); </code></pre> <p><a href="https://github.com/thinktecture/Thinktecture.IdentityModel.40/blob/master/IdentityModel/Thinktecture.IdentityModel/Tokens/Http/AuthenticationHandler.cs" rel="nofollow">REFERENCE</a></p> <p>The first request to the Web API works fine. All subsequent requests timeout. Using Fiddler, absolutely no response is received for anything after the first request. I thought it may be a caching issue, so I tacked on a couple headers:</p> <pre><code>Cache-Control: no-cache Pragma: no-cache Expires: -1 </code></pre> <p>But these had no effect. If I update the code to:</p> <pre><code>return base.SendAsync(request, cancellationToken).ContinueWith( (task) =&gt; { .. } , TaskContinuationOptions.ExecuteSynchronously ); </code></pre> <p>Then the issue is resolved.</p> <p>I've read that the order that configurations are applied in the Global.asax can affect MessageHandlers. I've tried rearranging these, but this did not seem to have any affect:</p> <pre><code>GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector), new AreaHttpControllerSelector(GlobalConfiguration.Configuration)); XmlConfigurator.Configure();//Applies Log4Net configuration AreaRegistration.RegisterAllAreas(); AuthenticationConfig.ConfigureGlobal(GlobalConfiguration.Configuration);//Applies Thinktecture's AuthenticationHandler FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Bootstrapper.Initialise();//Applies dependency injection </code></pre> <p>At the moment I have a solution, but it is unsatisfying because I do not understand the cause of the issue. Am I missing something obvious?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload