上传后图片无法刷新

时间:2013-12-22 14:27:52

标签: c# asp.net

我有奇怪的问题,我这样上传图片:

protected void UploadButton_Click(object sender, EventArgs e)
    {
        try
        {
            var row = MainUserGridView.SelectedRow;

            if (String.IsNullOrEmpty(row.Cells[0].Text)) return;

            var id = int.Parse(row.Cells[0].Text);

            var filePath = Server.MapPath("~//Upload");

            if (!Directory.Exists(filePath + "//user" + id + "//gfx"))
                Directory.CreateDirectory(filePath + "//user" + id + "//gfx");

            if (FileUploadControl.FileName.ToLower().Contains(".jpg"))
            {
                FileUploadControl.SaveAs(filePath + "//user" + id + "//gfx//photoInst.jpg");

            }
            photoInst.ImageUrl = "~/Upload/user" + id + "/gfx/photoInst.jpg";
            StatusLabel.Text = "File uploaded!";
        }
        catch (Exception ex)
        {
            StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
        }
    }

和photoInst是图像不刷新。但是当我点击f5时,图像将被刷新。有什么帮助吗?

1 个答案:

答案 0 :(得分:3)

听起来像浏览器正在缓存图像。对于ghetto修复,您可以使用时间戳将查询字符串添加到图像引用。

photoInst.ImageUrl = "~/Upload/user" + id + string.Format("/gfx/photoInst.jpg?{0}", DateTime.Now.Ticks);

看看它是否适合你。

祝你好运!