Here is my congure method in Startup file :
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddLog4Net("log4net.config");
//app.UseDeveloperExceptionPage();
app.UseExceptionHandler("/error");
app.UseMiddleware(typeof(Common.WebTools.MiddleWares.Log4netMiddleware));
app.UseMiddleware<Common.WebTools.MiddleWares.RequestBodyLoggingMiddleware>();
var options = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(options.Value);
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapControllerRoute("Empty","", new { controller = "Home", action = nameof(Controllers.HomeController.Index) });
endpoints.MapControllerRoute("Error", "error", new { controller = "Error", action = nameof(Controllers.ErrorController.Index) });
endpoints.MapControllerRoute("TunnelEnter", "enter", new { controller = "Home", action= nameof(Controllers.HomeController.Enter) });
endpoints.MapControllerRoute("TunnelCancel", "cancel", new { controller = "Home", action= nameof(Controllers.HomeController.Cancel) });
endpoints.MapControllerRoute("TunnelSuccess", "thankyou", new { controller = "Home", action = nameof(Controllers.HomeController.ThankYou) });
endpoints.MapFallbackToController(nameof(Controllers.HomeController.Index), "Home");
});
// use middleware and launch server for Vue
app.UseSpaStaticFiles(new StaticFileOptions {
OnPrepareResponse = ctx =>
{
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue { MaxAge = TimeSpan.FromDays(30*12) };
}
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "client-app";
if (env.IsDevelopment())
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:9001");
}
});
}
app.UseExceptionHandler("/error") doesn't raise anything, my "Index" method in "ErrorController" is never called. (If I call manually "/error" url, my custom page displays correctly.)
But if I use instead "app.UseDeveloperExceptionPage();", I have the system page with the error detailled.
What's wrong with my call ? "app.UseRouting()," is called after app.UseExceptionHandler as I saw here : Asp.Net 5/Core app.UseExceptionHandler() not working
UPDATE
After commenting line by line, I finally understand where the problem comes from. Here is my controller constructor
public HomeController(IHttpContextAccessor httpContextAccessor)
{
// If I comment the following line, it works !!!!
httpContextAccessor.HttpContext.Items.Add("a", "a");
}
I If comment the line, no problem. But why it doesn't work if the line is not commented ???? What happens with the context
Any idea?