1

I wrote Controller to handle 404-page error for my MVC5 application as it was showed here. However it works only with HTML-pages that has controller and method.

It doesn't work with files\images that just has a link inside the site. For example Sample.chtml:

    <a href="@material.FilePath"><i class="material-icons left">file_download</i>@material.Title</a>`

where FilePath is just reference to ~Content/images/... or ~/Content/Files/file.pdf.

When I try to go through this links I get standard 404 NotFound page and Error controller or Application_Error from Global.asax.cs doesn't call.

Especially I need this handler for file-not-found case. How can I solve this problem?

Edited : Important moment : this files has just pure-html-link and no controller\method defined.

Community
  • 1
  • 1
Iskander Raimbaev
  • 1,322
  • 2
  • 17
  • 35
  • Check this out https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging, http://benfoster.io/blog/aspnet-mvc-custom-error-pages you need to get past IIS default error pages. – pool pro May 22 '16 at 22:08

1 Answers1

2

Search NuGet for the MvcNotFound package. It handles all of this very neatly for you.

Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106