Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 74162c905f
Fetching contributors…

Cannot retrieve contributors at this time

59 lines (54 sloc) 2.073 kB
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace System.Web.Http.Tracing.Tracers
{
/// <summary>
/// Tracer for <see cref="AuthorizationFilterAttribute"/>
/// </summary>
internal sealed class AuthorizationFilterAttributeTracer : AuthorizationFilterAttribute
{
private const string OnAuthorizationMethodName = "OnAuthorization";
private readonly AuthorizationFilterAttribute _innerFilter;
private readonly ITraceWriter _traceStore;
public AuthorizationFilterAttributeTracer(AuthorizationFilterAttribute innerFilter, ITraceWriter traceStore)
{
_innerFilter = innerFilter;
_traceStore = traceStore;
}
public override void OnAuthorization(HttpActionContext actionContext)
{
_traceStore.TraceBeginEnd(
actionContext.ControllerContext.Request,
TraceCategories.FiltersCategory,
TraceLevel.Info,
_innerFilter.GetType().Name,
OnAuthorizationMethodName,
beginTrace: (tr) =>
{
HttpResponseMessage response = actionContext.Response;
if (response != null)
{
tr.Status = response.StatusCode;
}
},
execute: () => { _innerFilter.OnAuthorization(actionContext); },
endTrace: (tr) =>
{
HttpResponseMessage response = actionContext.Response;
if (response != null)
{
tr.Status = response.StatusCode;
}
},
errorTrace: (tr) =>
{
HttpResponseMessage response = actionContext.Response;
if (response != null)
{
tr.Status = response.StatusCode;
}
});
}
}
}
Jump to Line
Something went wrong with that request. Please try again.