I have this delegating handler in my api project:
class MyHandler : DelegatingHandler {
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken) {
var info = GrabSomeParametersFromHeader();
var isValid = await Validate(info); // this is a very light database query
if (!isValid) {
Log(request, info, false);
var response = new HttpResponseMessage(HttpStatusCode.Forbidden);
return response;
}
HttpContext.Current.SetMobileRequestInfo(info);
var result = await base.SendAsync(request, cancellationToken);
Log(request, info, result.IsSuccessStatusCode &&
result.StatusCode == HttpStatusCode.OK);
return result;
}
}
HttpContext.Current.SetMobileRequestInfo
simply adds the info
object to http-items to use later in app.
The Validate
is a very light database query. And the Log
method is inserting request's data (such as URI and query-string etc.) to database.
Sometimes, I'm getting a weird behavior of the app: it simply goes down! There is no log, no error, nothing. Just server doesn't response the requests. I have to restart app (for example by making a fake change in web.config
) to get it back to work. The app is a pretty simple app. I'm using ASP.NET Web API 2 on .NET 4.5 platform which is running on a IIS 7.5 machine. The only place I can think about is the mentioned delegating handler, which may cause the error. Do you have any idea? Does delegating handlers have any performance side effects which may cause the app to shut down?