using System;
|
using System.Collections.Generic;
|
using System.Diagnostics;
|
using System.IO;
|
using System.Linq;
|
using System.Net.Http;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Web;
|
using System.Web.Http.Filters;
|
using Pcb.Business.Authentication;
|
//using Pcb.Business.Biz;
|
using Pcb.Common;
|
using Pcb.Common.Enum;
|
using Pcb.Domain;
|
using Pcb.Infrastructure.Ioc;
|
|
namespace Pcb.Api.Infrastructures
|
{
|
/// <summary>
|
/// API Action Filter
|
/// </summary>
|
public class ActionInterceptAttribute : ActionFilterAttribute
|
{
|
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="actionContext"></param>
|
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
|
{
|
|
base.OnActionExecuting(actionContext);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="actionExecutedContext"></param>
|
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
|
{
|
base.OnActionExecuted(actionExecutedContext);
|
|
if (actionExecutedContext.Response != null)
|
{
|
actionExecutedContext.Response.Headers.Add("PerformanceMonitor","");
|
actionExecutedContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
|
if (AppConfigHelper.EnableReqLogging)
|
LogReqSuccessInfo(actionExecutedContext);
|
}
|
}
|
|
private void LogReqSuccessInfo(HttpActionExecutedContext actionExecutedContext)
|
{
|
var req = actionExecutedContext.Request;
|
if (actionExecutedContext.Response.StatusCode != System.Net.HttpStatusCode.InternalServerError)
|
{
|
IEnumerable<string> listPhoneType;
|
IEnumerable<string> listPhoneUniqueSign;
|
IEnumerable<string> listToken;
|
IEnumerable<string> listUserAgent;
|
req.Headers.TryGetValues("phone_type", out listPhoneType);
|
req.Headers.TryGetValues("phone_unique_sign", out listPhoneUniqueSign);
|
req.Headers.TryGetValues("token", out listToken);
|
req.Headers.TryGetValues("User-Agent", out listUserAgent);
|
var url = req.RequestUri.LocalPath;
|
var ip = Utils.GetIP();
|
var phoneType = listPhoneType == null ? "" : listPhoneType.Aggregate((a, b) => a + b);
|
var phoneUniqueSign = listPhoneType == null ? "" : listPhoneUniqueSign.Aggregate((a, b) => a + b);
|
var token = listToken == null ? "" : listToken.Aggregate((a, b) => a + b);
|
var userAgent = listUserAgent == null ? string.Empty : listUserAgent.Aggregate((a, b) => a + " " + b);
|
var member = WebAuthenticationContext.AppAuthenticationUser;
|
string info = string.Format("<br>地址:{0} 请求成功! <br> 参数: {1} <br> 耗时: {2}", url, req.RequestUri.Query,"");
|
int? memberId = null;
|
if (member != null) memberId = member.UserId;
|
//ThreadPool.QueueUserWorkItem(delegate { IocContainerManager.Container.Resolve<IApiLogApiBiz>().LogInfo(info, url, time , phoneType, ip, userAgent, memberId); });
|
}
|
}
|
}
|
}
|