请看下面的代码:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BSMS.Models;
using BSMS.BLL;public partial class ProjectMessage_GetImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.ShowImage();
} ProImage proimage = new ProImage();
ProImageManage proimagemng = new ProImageManage(); private void ShowImage()
{
try
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string imagestr = Request.QueryString["ImID"].ToString();
int imageid = Convert.ToInt16(imagestr); proimage = proimagemng.GetImageByID(imageid);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(proimage.ImageData);
}
catch (Exception ex)
{
//JScript.Alert(UpdatePanel1, ex.Message, this.Page);
JScript.Alert(ex.Message, this.Page);
}
finally
{ }
}
}我是用上面的一段代码向图片控件返回图片的。
问题是:当传送过来的ImID是相同的话,它不会重新运行该页面(类)的,返回的图片还是第一次调用的时候返回到图片。如果在数据库中,重新修改了图片,那么,他是不会返回新的图片的
请问:应该如何做修改?或者如何做?
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BSMS.Models;
using BSMS.BLL;public partial class ProjectMessage_GetImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.ShowImage();
} ProImage proimage = new ProImage();
ProImageManage proimagemng = new ProImageManage(); private void ShowImage()
{
try
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string imagestr = Request.QueryString["ImID"].ToString();
int imageid = Convert.ToInt16(imagestr); proimage = proimagemng.GetImageByID(imageid);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(proimage.ImageData);
}
catch (Exception ex)
{
//JScript.Alert(UpdatePanel1, ex.Message, this.Page);
JScript.Alert(ex.Message, this.Page);
}
finally
{ }
}
}我是用上面的一段代码向图片控件返回图片的。
问题是:当传送过来的ImID是相同的话,它不会重新运行该页面(类)的,返回的图片还是第一次调用的时候返回到图片。如果在数据库中,重新修改了图片,那么,他是不会返回新的图片的
请问:应该如何做修改?或者如何做?
<img src="ProjectMessage_GetImage.aspx&ImID=xx&t=<%= new Random().Next() %>" />
byte[] bytes = (byte[])SqlCommand.ExecuteScalar();
然后Response.ContentType = "application/jpeg";
然后就是BinaryWrite了.
Response.ContentType = "image/jpeg";//读写类型 一定要设置 否则浏览器会当作文本输出
Response.BinaryWrite((byte[])dt.Rows[0]["IMAGE"]);//图片数据