C#IE图片缓存不显示

出现问题:

上传了图片,点击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() + ""(参数);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值