Exemplo n.º 1
0
        public static HttpRequestModel Create(HttpRequestBase httpRequest)
        {
            var model = new HttpRequestModel
            {
                Id      = Guid.NewGuid(),
                DateUtc = DateTime.UtcNow,
                Method  = httpRequest.HttpMethod,
                Path    = httpRequest.RawUrl,
                Headers = string.Join(
                    Environment.NewLine,
                    httpRequest.Headers.AllKeys.Select(k => k + ": " + httpRequest.Headers[k])),
            };

            try
            {
                model.PostContent = httpRequest.Form.Count > 0
                    ? string.Join(
                    Environment.NewLine,
                    httpRequest.Form.ToDictionary()
                    .Where(x => x.Key != null)
                    .Select(x => x.Key + "=" + x.Value))
                    : null;
            }
            catch (Exception)
            {
            }
            return(model);
        }
Exemplo n.º 2
0
        private static HttpRequestModel GetOrCreateModel(HttpContextBase context)
        {
            var collection = GetOrCreateCollection(context);

            var model = (HttpRequestModel)context.Items[contextItemKey];

            if (model == null)
            {
                model = HttpRequestModel.Create(context.Request);
                if (IsEnabled(context))
                {
                    context.Items[contextItemKey] = model;
                }
            }

            if (IsEnabled(context) && !collection.Contains(model))
            {
                collection.Add(model);
            }

            return(model);
        }
 public static HttpRequestModel Create(HttpRequestBase httpRequest)
 {
     var model = new HttpRequestModel
     {
         Id = Guid.NewGuid(),
         DateUtc = DateTime.UtcNow,
         Method = httpRequest.HttpMethod,
         Path = httpRequest.RawUrl,
         Headers = string.Join(
             Environment.NewLine,
             httpRequest.Headers.AllKeys.Select(k => k + ": " + httpRequest.Headers[k])),
     };
     try
     {
         model.PostContent = httpRequest.Form.Count > 0
             ? string.Join(
                 Environment.NewLine,
                 httpRequest.Form.ToDictionary()
                     .Where(x => x.Key != null)
                     .Select(x => x.Key + "=" + x.Value))
             : null;
     }
     catch (Exception)
     {
     }
     return model;
 }