public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, IHostingEnvironment env) { FileProcessor fp = new FileProcessor(env); try { var havokcontext = fp.LoadJsonFromAppFolder("\\", "havok.json"); } catch { Havok havok = new Havok(); havok.Id = 1; havok.Name = "Item1"; string json = JsonConvert.SerializeObject(havok); fp.SaveJsonToAppFolder("\\", "havok.json", json); } Func <HttpContext, bool> isApiRequest = (HttpContext context) => context.Request.Path.ToString().StartsWith("/api/"); app.UseWhen(context => !isApiRequest(context), appbuilder => { appbuilder.UseHavokMiddleware(min: TimeSpan.FromMilliseconds(30000), max: TimeSpan.FromMilliseconds(40000)); }); // Configure Session. app.UseSession(); // Add static files to the request pipeline app.UseStaticFiles(); // Allow static files within the .well-known directory to allow for automatic SSL renewal app.UseStaticFiles(new StaticFileOptions() { ServeUnknownFileTypes = true, // this was needed as IIS would not serve extensionless URLs from the directory without it FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", @".well-known")), RequestPath = new PathString("/.well-known") }); // Add cookie-based authentication to the request pipeline app.UseAuthentication(); AppBuilderLoginProviderExtensions.AddLoginProviders(service, new ConfigurationLoginProviders(Configuration.GetSection("Authentication"))); // Add login providers (Microsoft/AzureAD/Google/etc). This must be done after `app.UseIdentity()` //app.AddLoginProviders( new ConfigurationLoginProviders(Configuration.GetSection("Authentication"))); // Add MVC to the request pipeline app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller}/{action}", defaults: new { action = "Index" }); routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }); routes.MapRoute( name: "api", template: "{controller}/{id?}"); }); }
public async Task Invoke(HttpContext httpContext, IHostingEnvironment env) { int delayInMs = _random.Value.Next(_minDelayInMs, _maxDelayInMs); FileProcessor fp = new FileProcessor(env); Havok myEnt = JsonConvert.DeserializeObject <Havok>(fp.LoadJsonFromAppFolder("\\", "havok.json")); if (myEnt.HavokEnabled == true && myEnt.isScaledOut == false) { await Task.Delay(delayInMs); } await _next(httpContext); }