public override void OnAuthorization(HttpActionContext actionContext) { try { base.OnAuthorization(actionContext); if (actionContext.RequestContext.Principal == null) { logger.LogWarning(correlation, "OnAuthorization - Principal is null."); } else if (actionContext.RequestContext.Principal.Identity == null) { logger.LogWarning(correlation, "OnAuthorization - Identity is null."); } else { IIdentity identity = actionContext.ControllerContext.RequestContext.Principal.Identity; if (identity.IsAuthenticated) { logger.LogVerbose(correlation, "OnAuthorization - User name: '{0}', auth type: '{1}'.", identity.Name, identity.AuthenticationType); } else { logger.LogWarning(correlation, "OnAuthorization - Identity is not authenticated. User name: '{0}', auth type: '{1}'.", identity.Name, identity.AuthenticationType); } } } catch (Exception e) { logger.LogError(correlation, e, "Authorization error."); } }
public override void OnActionExecuting(HttpActionContext actionContext) { if (actionContext == null) { throw new ArgumentNullException("actionContext"); } if (actionContext.ActionDescriptor == null) { throw new ArgumentException("HttpActionContext cannot have null ActionDescriptor.", "actionContext"); } if (actionContext.Request == null) { throw new ArgumentException("Request in HttpActionContext cannot be null.", "actionContext"); } if (actionContext.Request.Headers == null) { throw new ArgumentException("Headers in HttpActionContext.Request cannot be null.", "actionContext"); } logger.LogVerbose(correlation, "Request received: {0}({1})", actionContext.ActionDescriptor.ActionName, actionContext.ParametersToString()); }