2013-12-22 7 views
1

у меня есть странные проблемы, я загрузить изображение таким образом:изображения не обновить после загрузки

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, изображение будет обновлено. Любая помощь ?

ответ

2

Звучит так, как браузер кэширует изображение. Для исправления гетто вы можете добавить строку запроса к ссылке на изображение с меткой времени.

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

Посмотрите, работает ли это для вас.

Удачи вам!

Смежные вопросы