I have a bothersome problem with ASP.NET vNext; more specifically, MVC.
Here is a simplified version of my Startup.cs file:
public void ConfigureServices(IServiceCollection services) { // Add MVC services to the services container. services.AddMvc(); services.AddScoped<Foo>(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) { app.Use(async (context, next) => { await context.RequestServices.GetService<Foo>().Initialize(context); await next(); }); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }); }); // Time to save the cookie. app.Use((context, next) => { context.RequestServices.GetService<Foo>().SaveCookie(); return next(); }); }
The problem I am facing is very simple: the latest middleware in the request pipeline is not always called after app.UseMvc (). In fact, the only consistency I can make of this is that I only see .SaveCookie () is called at the start of a new session (or CTRL + F5).
Is there any rhyme or reason why my middleware is not always running?
source share