public WebCallInfo(EntityApp app, WebCallContextHandlerSettings settings, HttpRequestMessage request, CancellationToken cancellationToken) { Request = request; WebContext = new WebCallContext(request, app.TimeService.UtcNow, app.TimeService.ElapsedMilliseconds, GetIncomingCookies, GetIncomingHeaderValues); WebContext.OperationContext = new OperationContext(app, UserInfo.Anonymous, WebContext, settings.ConnectionReuseMode); WebContext.OperationContext.SetExternalCancellationToken(cancellationToken); Request.Properties[WebCallContext.WebCallContextKey] = WebContext; WebContext.RequestUrl = request.RequestUri.ToString(); WebContext.HttpMethod = request.Method.ToString().ToUpperInvariant(); WebContext.RequestSize = request.Content.GetLength(); //Check if it is one of the sensitive URLs var path = request.RequestUri.LocalPath; // The only way to get IPaddress it seems is thru use of HttpContext (from ASP.NET host). // NOTE: it is available only under ASP.NET/IIS host, not in self-hosting scenario var ctxWrapper = WebHelper.GetHttpContextWrapper(request); if (ctxWrapper != null) { //IIS hosting WebContext.Referrer = ctxWrapper.Request.UrlReferrer + string.Empty; WebContext.IPAddress = ctxWrapper.Request.UserHostAddress; } else { //Self hosting // webCallContext.IPAddress = "(unknown)"; } //Set log level for this call WebContext.OperationContext.LogLevel = settings.LogLevel; }
public static void ConfigureWebApi(HttpConfiguration httpConfiguration, EntityApp app, LogLevel logLevel = LogLevel.Basic, WebHandlerOptions webHandlerOptions = WebHandlerOptions.DefaultDebug) { // Logging message handler var webHandlerStt = new WebCallContextHandlerSettings(logLevel, webHandlerOptions); var webContextHandler = new WebCallContextHandler(app, webHandlerStt); httpConfiguration.MessageHandlers.Add(webContextHandler); // Exception handling filter - to handle/save exceptions httpConfiguration.Filters.Add(new ExceptionHandlingFilter()); // Formatters - add formatters with spies, to catch/log deserialization failures httpConfiguration.Formatters.Clear(); httpConfiguration.Formatters.Add(new StreamMediaTypeFormatter("image/jpeg", "image/webp")); //webp is for Chrome var xmlFmter = new XmlMediaTypeFormatter(); httpConfiguration.Formatters.Add(xmlFmter); var jsonFmter = new JsonMediaTypeFormatter(); // add converter that will serialize all enums as strings, not integers jsonFmter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); var resolver = jsonFmter.SerializerSettings.ContractResolver = new JsonContractResolver(jsonFmter); httpConfiguration.Formatters.Add(jsonFmter); //Api configuration if (app.ApiConfiguration.ControllerInfos.Count > 0) ConfigureSlimApi(httpConfiguration, app); }
public WebCallContextHandler(EntityApp app, WebCallContextHandlerSettings settings) { App = app; Settings = settings ?? new WebCallContextHandlerSettings(); App.RegisterConfig(Settings); _webCallLog = App.GetService<IWebCallLogService>(); _errorLog = App.GetService<IErrorLogService>(); App.RegisterService<IWebCallNotificationService>(this); }
public WebCallContextHandler(EntityApp app, WebCallContextHandlerSettings settings) { App = app; Settings = settings ?? new WebCallContextHandlerSettings(); App.RegisterConfig(Settings); _webCallLog = App.GetService <IWebCallLogService>(); _errorLog = App.GetService <IErrorLogService>(); _sessionService = App.GetService <IUserSessionService>(); App.RegisterService <IWebCallNotificationService>(this); }
public static void ConfigureWebApi(HttpConfiguration httpConfiguration, EntityApp app, LogLevel logLevel = LogLevel.Basic, WebHandlerOptions webHandlerOptions = WebHandlerOptions.DefaultDebug, ApiNameMapping nameMapping = ApiNameMapping.Default) { // Logging message handler var webHandlerStt = new WebCallContextHandlerSettings(logLevel, webHandlerOptions); var webContextHandler = new WebCallContextHandler(app, webHandlerStt); httpConfiguration.MessageHandlers.Add(webContextHandler); // Exception handling filter - to handle/save exceptions httpConfiguration.Filters.Add(new ExceptionHandlingFilter()); // Formatters - add formatters with spies, to catch/log deserialization failures httpConfiguration.Formatters.Clear(); httpConfiguration.Formatters.Add(new StreamMediaTypeFormatter("image/jpeg", "image/webp")); //webp is for Chrome var xmlFmter = new XmlMediaTypeFormatter(); httpConfiguration.Formatters.Add(xmlFmter); var jsonFmter = new JsonMediaTypeFormatter(); // add converter that will serialize all enums as strings, not integers jsonFmter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); jsonFmter.SerializerSettings.ContractResolver = new JsonNameContractResolver(nameMapping); jsonFmter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Unspecified; httpConfiguration.Formatters.Add(jsonFmter); //Api configuration if (app.ApiConfiguration.ControllerInfos.Count > 0) { ConfigureSlimApiControllers(httpConfiguration, app); } app.RegisterService <IBackgroundTaskService>(new WebBackgroundTaskService(app)); }
public WebCallInfo(EntityApp app, WebCallContextHandlerSettings settings, HttpRequestMessage request) { Request = request; WebContext = new WebCallContext(request, app.TimeService.UtcNow, app.TimeService.ElapsedMilliseconds, GetIncomingCookies, GetIncomingHeaderValues); WebContext.OperationContext = new OperationContext(app, UserInfo.Anonymous, WebContext, settings.ConnectionReuseMode); Request.Properties[WebCallContext.WebCallContextKey] = WebContext; WebContext.RequestUrl = request.RequestUri.ToString(); WebContext.HttpMethod = request.Method.ToString().ToUpperInvariant(); WebContext.RequestSize = request.Content.GetLength(); //Check if it is one of the sensitive URLs var path = request.RequestUri.LocalPath; // The only way to get IPaddress it seems is thru use of HttpContext (from ASP.NET host). // NOTE: it is available only under ASP.NET/IIS host, not in self-hosting scenario var ctxWrapper = WebHelper.GetHttpContextWrapper(request); if (ctxWrapper != null) { //IIS hosting WebContext.Referrer = ctxWrapper.Request.UrlReferrer + string.Empty; WebContext.IPAddress = ctxWrapper.Request.UserHostAddress; } else { //Self hosting // webCallContext.IPAddress = "(unknown)"; } //Set log level for this call WebContext.OperationContext.LogLevel = settings.LogLevel; }