我正在使用处理程序显示来自数据库的员工简档图像。图像在Internet Explorer中显示效果良好,但未在Chrome和Firefox中显示。 可能是什么问题?在Chrome和FF中未显示图像处理程序图像
这里是我的代码:
ASPX:
<% img_profile.ImageUrl="~/Handler.ashx?empcd="+Session["empcd"].ToString() ;
%>
<asp:Image CssClass="img-rounded img-responsive profile" runat="server" ID="img_profile" Width="150" Height="150" />
图像处理代码:
public void ProcessRequest(HttpContext context)
{
try
{
OracleDataReader rdr = null;
OracleConnection dbConn;
dbConn = Conn.getConn();
string empcd = context.Request.QueryString["empcd"].ToString();
OracleCommand cmd = new OracleCommand("select photo img from olphrm.emp_personal where emp_code='"+empcd+"'", dbConn);
dbConn.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
context.Response.BinaryWrite((byte[])rdr["img"]);
}
if (rdr != null)
rdr.Close();
}
catch (Exception ex)
{
}
}
这是在Chrome输出:
[! [在这里输入图像描述] [1]] [1]
在此先感谢您的帮助!
UPDATE:
我已经添加下面的代码在我的aspx页面,现在显示的图像person.png,这意味着有任何错误我。怎么可以找到并解决这个问题?
<% img_profile.ImageUrl="~/Handler.ashx?empcd="+Session["empcd"].ToString() ;
img_profile.Attributes["onerror"] = "this.src='Images/person.png';";
%>
如何以及应该在哪里调用此方法? –
只是修改了答案。 改为: context.Response.BinaryWrite((byte [])rdr [“img”]); –
我试过了,不工作 –