简体   繁体   中英

How to handle 404 error for files in MVC5?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM