我正在尝试从另一个 Intranet 站点获取用户的缩略图,但其中一些不遵循预定义的格式,这意味着我想改为加载默认缩略图。
检查图像 URL 是否有效的最佳方法是什么?
最佳答案
根据您获取图像的方式,这可能会有所不同
<html>
<body>
<img src="<dynamic handler url>" alt="My Username" onError="this.src='defaultProfile.jpg';" />
</body>
</html>
这就是您在 ASP.NET 中的做法。
设计师-
<asp:Image ImageUrl="NonexistentImage.Jpg" ID="profileImage" Height="50" Width="50" runat=server />
代码隐藏(c#)
profileImage.Attributes["onerror"] = "this.src='http://www.cs.uofs.edu/~olivetoj2/blah.jpg';";
这非常适合我。
关于c# - asp.net 检查 imageURL 是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10812985/