Question

I've got a grid which provides some links for users to download files. Files are stored outside of the application, the path references are read from the database and a HTTP handler (*.ashx) is used to serve each requested file. It is, however, possible that there could be a database entry pointing to a non existent file. I catch the FileNotFoundException, but I'm not sure what would be the best method to inform the user of the missing file (so that they can contact support).

First idea is to set a standard 404 code on the response, and that's what I'm doing now.

A more helpful way would be to display a notification (jQuery) about a missing file, but the file download is not done in AJAX, so this would involve a two step process - a client side onclick handler calls a web service method to check if the file exists, if not, then I cancel the click (return false) and display a friendly message to the user. If the file exists however, I proceed with the normal execution. But this adds yet another server call.

Have you dealt with a similar problem? How did you solve it?

Some clarifications - the application is built in ASP.NET 2.0 and uses jQuery to call the web service methods.

Was it helpful?

Solution

Pawel, it seems you've answered your question already...

...(so that they can contact support)...

By stating the above I would suggest you create a custom 404 page which notifies the user of the file not existing on disk and provide them information on how to get in contact with the support office.

I've created a HTTP Handler for handling files and if a file does not exist on disk then I return a 404 response. I've setup IIS to display a custom page if a 404 reponse has been thrown.. (and I do the same for error 500).

Hope this helps and good luck with finding the solution that fits your needs!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top