我有一个ashx文件,通过它我想获得一个asp图像控件的图像。下面的代码是一个ashx文件
SqlConnection con = null;
SqlDataReader dr = null; SqlCommand cmd = null;
try
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["GalleriaDatabaseConnectionString"].ConnectionString);
cmd = new SqlCommand("Select Image from tblImage where UserName='" + context.Session["uname"] + "'");
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite((byte[])dr["Image"]);
dr.Close();
}
}**
答案 0 :(得分:0)
在ImageUr属性中提及ashx文件的路径。如下所示
<asp:Image runat='server' Id='image' ImageUrl='imageprocessor.ashx'></asp:Image>