Skip to content

Instantly share code, notes, and snippets.

@spboyer
Created August 17, 2018 14:30
Show Gist options
  • Save spboyer/d16e44a24af601eb0b4ac9fbc210cfe6 to your computer and use it in GitHub Desktop.
Save spboyer/d16e44a24af601eb0b4ac9fbc210cfe6 to your computer and use it in GitHub Desktop.
Azure CDN Image Tag Helper Error Handling
//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