Merge pull request #257 from suhasj/UpdateErrorHandler

Added Error Handler middleware and Configure methods based on compilatio...
This commit is contained in:
Suhas Joshi 2014-10-14 16:17:28 -07:00
commit b2d346769a
2 changed files with 33 additions and 4 deletions

View File

@ -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<Album> GetTopSellingAlbums(int count)
{
// Group the order details by album and return

View File

@ -97,12 +97,34 @@ namespace MusicStore
services.AddInstance<IMemoryCache>(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();