我正在使用處理程序顯示來自數據庫的員工簡檔圖像。圖像在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」]); –
我試過了,不工作 –