views:

382

answers:

1

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.

+1  A: 

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!

Zaagmans
But then I can't differentiate between a missing file situation and that when a whole page is missing. I could provide some more elaborate explanation on the 404 page, such as "if you were trying to download a file contact support, if you were trying to access a page it can't be found", etc.)...
Pawel Krakowiak
Well you could implement in your HTTP handler to redirect to a file not found specific 404 page, otherwise return a 'normal' 404?
Zaagmans
Doh! Of course the redirect works! I was relying on the Framework to redirect to the 404 page by passing a status code, instead of doing a simple Response.Redirect(). So obvious... Thanks!
Pawel Krakowiak