5

So I've been struggling to catch database related errors for example if SQL database is down or unavailable, I've get error thrown by the code and website displays a blank page, and if I use app.UseDeveloperExceptionPage(); in Configure method it works fine, but when I am trying to use

either

 app.UseStatusCodePagesWithRedirects("/error?error={0}");

or

 app.UseExceptionHandler("/error?error={0}");

Nothing happens, just a blank page is displayed, catching other errors such as 404 and so on works just fine. What is a proper way catch all general errors in .NET Core MVC project?

Aistis Taraskevicius
  • 781
  • 2
  • 10
  • 31
  • 1
    perhaps http://stackoverflow.com/questions/21993758/asp-net-mvc-5-error-handling can help you out – Wouter van Vegchel Mar 20 '17 at 12:43
  • @WoutervanVegchel seems overly complicated for what I need and .Net Core MVC projects are structured and handled differently, so its not really applicable – Aistis Taraskevicius Mar 20 '17 at 12:57
  • Mabey a more apropriate question would be:"How to handle errors in .net MVC". And i can tell you if you google for a couple of minutes you'll have more answers than you can handle. – SomeRandomName Mar 20 '17 at 13:31
  • @SomeRandomName I do not need old and outdates ways to handle errors in .net mvc. Core is a different beasts and handles projects all together different. There are officials tutorials for error handling, but it does not work for connection errors to the database, which Is what I am asking for.. – Aistis Taraskevicius Mar 20 '17 at 14:35
  • I have run into this same issue, did you manage to find a solution? – Malrig Oct 13 '17 at 12:52
  • No, I haven't touched the project that required it for a while, I am not sure if Net Core 2.0 fixed that or its still an issue. One suggestion I can make is to wrap database initiation ( in startup.cs) in try and catch method and display error if its down. Same can probably be done for some other errors that are not handled automatically. – Aistis Taraskevicius Oct 13 '17 at 14:26
  • you need to use error logging here, configured at startup level. i use serilog for this.. if you think its useful in your case i can share my working code. – Alok Apr 01 '22 at 13:12

0 Answers0