public void Configuration(IAppBuilder app) { var configuration = new HttpConfiguration(); // enable logging configuration.Filters.Add(new DiagnosticsFilterAttribute()); // Web API configuration and services // CORS Attribute configuration.EnableCors(CorsManager.CorsAttribute()); // Ensure HTTPS over TLS 1.2 for External and Prod SecurityProtocolManager.SetSecurityProtocol(); // Set application specific Json Serialization settings SerializerManager.ApplyCustomSettings(configuration.Formatters); // Web API routes and application routes RoutesManager.AddRoutes(configuration); // Owin level exception handling app.Use <GlobalExceptionMiddleware>(); // IoC and DI configuration configuration.DependencyResolver = ConfigureIocResolver(); // Middleware for properties stored on the LogicalThreadContext for log4net and other purposes app.Use <RequestMetadataMiddleware>(); var authMiddleware = (AuthMiddleware)configuration.DependencyResolver.GetService(typeof(IAuthMiddleware)); app.Use(async(context, next) => { await authMiddleware.Invoke(context, next); }); // Global exception handler for AC errors configuration.Filters.Add(new MgiExceptionFilter()); // Filter to add custom headers to the response configuration.Filters.Add(new HeaderFilter()); AwMapper.Configure(); // Web API documentation configuration // Web API documentation for environments that have ApiDocumentation app key set to true var keyName = "ApiDocumentation"; var apiDocKeyExists = ConfigurationManager.AppSettings.AllKeys.Contains(keyName); if (apiDocKeyExists && bool.Parse(ConfigurationManager.AppSettings[keyName])) { ApiDocumentationManager.Configure(configuration); } app.UseWebApi(configuration); }