예제 #1
0
        protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            //由token換成userid

            string userid        = "null";
            var    token         = Enumerable.Empty <string>();
            bool   isHeaderExist = request.Headers.TryGetValues(_header, out token);

            if (isHeaderExist)
            {
                if (token.Count() > 0)
                {
                    authFunc auth = new authFunc();
                    userid = auth.validatesToken(token.First());
                }
            }

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var info = new RequestLogInfo
            {
                HttpMethod  = request.Method.Method,
                UrlAccessed = request.RequestUri.AbsoluteUri,
                IpAddress   = HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : "0.0.0.0",
                RequestTime = DateTime.Now,
                Token       = this.GetToken(request),
                Signature   = userid,
                Timestamp   = this.GetTimestamp(request),
                BodyContent = request.Content == null ? string.Empty : request.Content.ReadAsStringAsync().Result
            };

            var logContent = this._serializer.Serialize <RequestLogInfo>(info);

            this._log.Save(logContent);

            return(request);
        }
예제 #2
0
 public string Serialize <T>(RequestLogInfo info)
 {
     //return info.IpAddress + "|" + info.RequestTime + "|" + info.Signature + "|" + info.HttpMethod + "|" + info.UrlAccessed + "|" + info.BodyContent;
     return("{userid:" + info.Signature + "},{ip:" + info.IpAddress + "},{method:" + info.HttpMethod + "},{time:" + info.RequestTime.ToString("yyyy/MM/dd HH:mm:ss") + "},{request:" + info.UrlAccessed + "}");
 }