asp.net检查是否存在IMAGEURL [英] asp.net check if imageURL exists
本文介绍了asp.net检查是否存在IMAGEURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从另外一个内部网站,但他们中的一些获得了用户的缩略图不按照预先定义的格式,这意味着我会想,而不是加载了一个默认的缩略图。
I am trying to get a user's thumbnail from another intranet site but some of them do not follow the pre-defined format meaning I would want to load up a default thumbnail instead.
请告诉我检查图像的URL是否有效的最好方法是什么?
Whats the best way to check if an image URL is valid?
推荐答案
根据你如何让你的图片这种变化可能会奏效
Depending on how you are getting your images a variation of this might work
<html>
<body>
<img src="<dynamic handler url>" alt="My Username" onError="this.src='defaultProfile.jpg';" />
</body>
</html>
这是你会怎么做它在ASP.NET。
This is how you would do it in ASP.NET.
设计师 -
<asp:Image ImageUrl="NonexistentImage.Jpg" ID="profileImage" Height="50" Width="50" runat=server />
代码隐藏(C#)
Code Behind (c#)
profileImage.Attributes["onerror"] = "this.src='http://www.cs.uofs.edu/~olivetoj2/blah.jpg';";
这完全适用于我。
这篇关于asp.net检查是否存在IMAGEURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文