//constructor public WebCallContextHandlerSettings(LogLevel logLevel = LogLevel.Basic, WebHandlerOptions options = WebHandlerOptions.DefaultDebug, string sessionToken = "Authorization", WebTokenType sessionTokenType = WebTokenType.Header, string versionToken = DefaultVersionToken, string csrfToken = null, DbConnectionReuseMode connectionReuseMode = DbConnectionReuseMode.KeepOpen) { LogLevel = logLevel; Options = options; ConnectionReuseMode = connectionReuseMode; if (sessionToken != null) { TokenHandlers.Add(new WebSessionTokenHandler(sessionToken, sessionTokenType)); } if (versionToken != null) { TokenHandlers.Add(new VersionTokenHandler(versionToken)); } // Cross-Site Request Forgery (CSRF) protection. Used as header only (not cookie), when session token is saved in cookie, // to protect against CSRF execution. Sometimes called synchronization token; read more in Wikipedia or other resources if (csrfToken != null) { TokenHandlers.Add(new WebTokenHandler(csrfToken, WebTokenType.Header, WebTokenDirection.InputOutput)); } //We ignore Swagger paths by default IgnorePaths.Add("/swagger"); }
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); }
//constructor public WebCallContextHandlerSettings(LogLevel logLevel = LogLevel.Basic, WebHandlerOptions options = WebHandlerOptions.DefaultDebug, string sessionToken = "Authorization", WebTokenType sessionTokenType = WebTokenType.Header, string versionToken = DefaultVersionToken, string csrfToken = null, DbConnectionReuseMode connectionReuseMode = DbConnectionReuseMode.KeepOpen) { LogLevel = logLevel; Options = options; ConnectionReuseMode = connectionReuseMode; if (sessionToken != null) TokenHandlers.Add(new WebSessionTokenHandler(sessionToken, sessionTokenType)); if (versionToken != null) TokenHandlers.Add(new VersionTokenHandler(versionToken)); // Cross-Site Request Forgery (CSRF) protection. Used as header only (not cookie), when session token is saved in cookie, // to protect against CSRF execution. Sometimes called synchronization token; read more in Wikipedia or other resources if (csrfToken != null) TokenHandlers.Add(new WebTokenHandler(csrfToken, WebTokenType.Header, WebTokenDirection.InputOutput)); //We ignore Swagger paths by default IgnorePaths.Add("/swagger"); }
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 static bool IsSet(this WebHandlerOptions options, WebHandlerOptions option) { return((options & option) != 0); }
public static bool IsSet(this WebHandlerOptions options, WebHandlerOptions option) { return (options & option) != 0; }