Search code examples
exceptionimageresizer

Handle FileNotFoundException thrown by ImageResizer.AzureReader2 (BlobNotFound)


I'm running an MVC app on Azure. I use the AzureReader2 plugin. It's been working fine for years.

But when this hits missing images, it throws FileNotFoundException exception and this apparently breaks down user authentication, causing user to be redirected to login page.

Is there a way to prevent this? How can I catch and handle this exception for the URL API?

I am considering the Image404 plugin. But I am not sure it works with AzureReader2 plugin (?)

Exception handling would be best for me as I could take some other actions.

Thanks


Solution

  • You can see the Image404 plugin source code on GitHub. There is a Config.Current.Pipeline.ImageMissing event that it handles - you can plug into the same event to do your own logic.

    It should work fine with AzureReader2.

    Note that most likely your 404 page is set to require authentication, which is why it is redirecting.