C#IE图片缓存不显示
2009-06-15 17:37
113 查看
出现问题:
上传了图片,点击DataGridView某列,显示图片进行预览.使用BiraryWrite进行读取,然后放在Image控件中显示.
主要代码如下:
//用来显示图片的方法
private void showImag(string strID)
{
//三张图片,分别实例化三个BinaryWriter
BinaryWriter B_bw = null;
BinaryWriter M_bw = null;
BinaryWriter S_bw = null;
try
{
string strsql = "select B_ImageData,M_ImageData,S_ImageData from showimage where id=" + strID + "";
DataTable dt = con.GetData(strsql, "showimage");
if (dt.Rows.Count > 0)
{
//从数据库读取Image二进制数据流
Byte[] B_image = (Byte[])dt.Rows[0][0];//第一张
Byte[] M_image = (Byte[])dt.Rows[0][1];//第二张
Byte[] S_image = (Byte[])dt.Rows[0][2];//第三张
string strB_Path = "~/image/Bwangwu.jpg";//存放图片的文件夹路径.
string strM_Path = "~/image/Mwangwu.jpg";
string strS_Path = "~/image/Swangwu.jpg";
//返回与Web服务器上的指定虚拟路径相对应的物理文件路径.
string strBPath = Server.MapPath(strB_Path);
string strMPath = Server.MapPath(strM_Path);
string strSPath = Server.MapPath(strS_Path);
//实例化BinaryWriter
B_bw = new BinaryWriter(File.Open(strBPath, FileMode.Create));
M_bw = new BinaryWriter(File.Open(strMPath, FileMode.Create));
S_bw = new BinaryWriter(File.Open(strSPath, FileMode.Create));
//输出流
B_bw.Write(B_image);
M_bw.Write(M_image);
S_bw.Write(S_image);
//注意以下带参数,用作显示图片
this.B_Image.ImageUrl = strB_Path + "?dd=" + Guid.NewGuid() + "";
this.M_Image.ImageUrl = strM_Path + "?dd=" + Guid.NewGuid() + "";
this.S_Image.ImageUrl = strS_Path + "?dd=" + Guid.NewGuid() + "";
B_bw.Flush();
M_bw.Flush();
S_bw.Flush();
B_bw.Close();
M_bw.Close();
S_bw.Close();
}
}
catch(Exception ea)
{
B_bw.Close();
M_bw.Close();
S_bw.Close();
}
在本地测试没有问题.放在IIS中,服务器图片已更新,点击客户连接,显示不到最新的图片.只能按F5刷新,才能显示最新的,想到可能是IE缓存的问题.
解决方法:
第一,可以在Internet选项-> 常规->设置> 每次访问此页时检查.此时每次得到的页面都是最新的.
第二,在显示图片的路径文件中添加参数,使其每次得到的图片都是最新的.
this.S_Image.ImageUrl (Image的路径) = (从数据库中读取到的数据库文件,保存到本地的路径)strS_Path + "?dd=" + Guid.NewGuid() + ""(参数);
上传了图片,点击DataGridView某列,显示图片进行预览.使用BiraryWrite进行读取,然后放在Image控件中显示.
主要代码如下:
//用来显示图片的方法
private void showImag(string strID)
{
//三张图片,分别实例化三个BinaryWriter
BinaryWriter B_bw = null;
BinaryWriter M_bw = null;
BinaryWriter S_bw = null;
try
{
string strsql = "select B_ImageData,M_ImageData,S_ImageData from showimage where id=" + strID + "";
DataTable dt = con.GetData(strsql, "showimage");
if (dt.Rows.Count > 0)
{
//从数据库读取Image二进制数据流
Byte[] B_image = (Byte[])dt.Rows[0][0];//第一张
Byte[] M_image = (Byte[])dt.Rows[0][1];//第二张
Byte[] S_image = (Byte[])dt.Rows[0][2];//第三张
string strB_Path = "~/image/Bwangwu.jpg";//存放图片的文件夹路径.
string strM_Path = "~/image/Mwangwu.jpg";
string strS_Path = "~/image/Swangwu.jpg";
//返回与Web服务器上的指定虚拟路径相对应的物理文件路径.
string strBPath = Server.MapPath(strB_Path);
string strMPath = Server.MapPath(strM_Path);
string strSPath = Server.MapPath(strS_Path);
//实例化BinaryWriter
B_bw = new BinaryWriter(File.Open(strBPath, FileMode.Create));
M_bw = new BinaryWriter(File.Open(strMPath, FileMode.Create));
S_bw = new BinaryWriter(File.Open(strSPath, FileMode.Create));
//输出流
B_bw.Write(B_image);
M_bw.Write(M_image);
S_bw.Write(S_image);
//注意以下带参数,用作显示图片
this.B_Image.ImageUrl = strB_Path + "?dd=" + Guid.NewGuid() + "";
this.M_Image.ImageUrl = strM_Path + "?dd=" + Guid.NewGuid() + "";
this.S_Image.ImageUrl = strS_Path + "?dd=" + Guid.NewGuid() + "";
B_bw.Flush();
M_bw.Flush();
S_bw.Flush();
B_bw.Close();
M_bw.Close();
S_bw.Close();
}
}
catch(Exception ea)
{
B_bw.Close();
M_bw.Close();
S_bw.Close();
}
在本地测试没有问题.放在IIS中,服务器图片已更新,点击客户连接,显示不到最新的图片.只能按F5刷新,才能显示最新的,想到可能是IE缓存的问题.
解决方法:
第一,可以在Internet选项-> 常规->设置> 每次访问此页时检查.此时每次得到的页面都是最新的.
第二,在显示图片的路径文件中添加参数,使其每次得到的图片都是最新的.
this.S_Image.ImageUrl (Image的路径) = (从数据库中读取到的数据库文件,保存到本地的路径)strS_Path + "?dd=" + Guid.NewGuid() + ""(参数);
相关文章推荐
- C#控制IE进程关闭和缓存清理的实现代码
- C# 解决调用winform窗体顶置且解决任务栏图片显示问题
- Xlistview 多条目 图片错位 使用图片缓存显示图片
- 如何使IE地址栏里显示自己的小图片?
- c# asp.net 使用kindeditor在服务器上不能显示上传图片的页面等解决办法
- Rails WEBrick 服务器问题:ie下不能显示图片,图片放在public目录下的,chrome可以显示
- C#SoapFormatter序列化一例:将图片读写入xml文件,并能根据需要在PictureBox中按比例缩小显示
- C#SoapFormatter序列化一例:将图片读写入xml文件,并能根据需要在PictureBox中按比例缩小显示
- C# wpf image绑定viewModel没有显示图片
- jpg格式的图片,在ie下不显示
- 图片在ie下无法正常显示,在firefox或chrome正常显示的原因
- c#get网页图片并显示在picturebox上
- IE6下透明PNG图片的显示
- 【Android Training - 09】高效地显示Bitmap图片 [ Lesson 3 - 两种缓存Bitmap的方式 ]
- xcode替换同名图片后,显示的还是旧图片。各种清除缓存都没有解决问题
- C#实现将Email地址转成图片显示的方法
- C# WPF 显示图片和视频显示 EmuguCv、AForge.Net测试
- fancybox1.3.1 基于Jquery的插件在IE中图片显示问题
- 想在C#中的listView 控件中显示图片:
- IE下background背景图片无法显示问题解决方法