diff --git a/src/MusicStore/Controllers/HomeController.cs b/src/MusicStore/Controllers/HomeController.cs index 2bf2e2e997..b91b6c64ed 100644 --- a/src/MusicStore/Controllers/HomeController.cs +++ b/src/MusicStore/Controllers/HomeController.cs @@ -34,6 +34,13 @@ namespace MusicStore.Controllers return View(albums); } + //Can be removed and handled when HandleError filter is implemented + //https://github.com/aspnet/Mvc/issues/623 + public IActionResult Error() + { + return View("~/Views/Shared/Error.cshtml"); + } + private List GetTopSellingAlbums(int count) { // Group the order details by album and return diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 95d08c2c72..4d49de0ec0 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -97,12 +97,34 @@ namespace MusicStore services.AddInstance(new MemoryCache()); } + //This method is invoked when KRE_ENV is 'Development' or is not defined + //The allowed values are Development,Staging and Production + public void ConfigureDevelopment(IApplicationBuilder app) + { + //Display custom error page in production when error occurs + //During development use the ErrorPage middleware to display error information in the browser + app.UseErrorPage(ErrorPageOptions.ShowAll); + Configure(app); + } + + //This method is invoked when KRE_ENV is 'Staging' + //The allowed values are Development,Staging and Production + public void ConfigureStaging(IApplicationBuilder app) + { + app.UseErrorHandler("/Home/Error"); + Configure(app); + } + + //This method is invoked when KRE_ENV is 'Production' + //The allowed values are Development,Staging and Production + public void ConfigureProduction(IApplicationBuilder app) + { + app.UseErrorHandler("/Home/Error"); + Configure(app); + } + public void Configure(IApplicationBuilder app) { - //Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline. - //Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. - app.UseErrorPage(ErrorPageOptions.ShowAll); - // Add services from ConfigureServices app.UsePerRequestServices();