Created
August 17, 2018 14:30
Azure CDN Image Tag Helper Error Handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Retrieve any existing onerror handler code | |
var onError = output.Attributes[OnErrorAttributeName] ? .Value as string; | |
//Check if there's a fallback source and no onerror handler | |
if (!string.IsNullOrWhiteSpace(FallbackSrc) && string.IsNullOrWhiteSpace(onError)) { | |
string resolvedUrl; | |
if (TryResolveUrl(FallbackSrc, out resolvedUrl)) { | |
FallbackSrc = resolvedUrl; | |
} | |
if (AppendVersion) { | |
FallbackSrc = _fileVersionProvider.AddFileVersionToPath(FallbackSrc); | |
} | |
//Apply fallback handler code | |
onError = $ "this.src='{FallbackSrc}';console.log('{Src} NOT FOUND.')"; | |
output.Attributes.SetAttribute(OnErrorAttributeName, onError); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment