Handling Errors in ExecuteResult ASP.NET MVC
I have a file DownloadResult.cs extended from ActionResult(actually cloned from Phil Haack's one, which u can fi开发者_JAVA技巧nd at the following location Phil's blog )
Here how do i handle an exception(file not found ) thrown from the method ExecuteResult() in the controller level .
for the source code you might want to look at Phil's code , which is available at the link provided above.
looking forward for ur thoughts .
thanks, vijay
You should implement a global error catching mechanism.
I recommend the approach explained in this question How can I properly handle 404s in ASP.NET MVC?
If you want a nicer message in your action result, you simply can add a try catch
block and if the file does not exists:
Throw New HttpException(404, "The file you want to download does not exists.")
精彩评论