在asp.net中找不到图像时显示默认图像? [英] Display Default Image when No Image Found in asp.net?

查看:121
本文介绍了在asp.net中找不到图像时显示默认图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:Image ID="imageprofile" runat="server" Width="150" Height="150" CssClass="image"  onerror="this.onload = null; this.src='images/Gravatar.jpg';"/>





无法使用代码



not working above code

推荐答案

尝试 onError -
<asp:image id="imageprofile" runat="server" width="150" height="150" cssclass="image" onerror="this.onload = null; this.src='images/Gravatar.jpg';" xmlns:asp="#unknown" />


这里 [ ^ ]是另一种方法在IIS本身使用重写规则呈现:



Here[^] is an other approach presented using rewrite rule in IIS itself:

<rewrite>
            <rules>
                <rule name="RewriteNoneExist">
                    <match url="^gfx/([0-9]+).png


/ >
< 条件 >
< 添加 输入 = {REQUEST_FILENAME} matchType = IsFile 否定 = true / >
< / conditions >
< action 类型 = 重写 url = gfx / default.png / >
< / rule >
< / rules >
< / rewrite >
" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="gfx/default.png" /> </rule> </rules> </rewrite>



当然,您需要对其进行优化。


Of course, you will need to refine it.


这篇关于在asp.net中找不到图像时显示默认图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆