【问题标题】:Images show up in Dev build but dont show up after publishing the project asp.net图像显示在 Dev 构建中,但在发布项目 asp.net 后不显示
【发布时间】:2015-07-13 17:33:45
【问题描述】:

我从数据库中获取二进制字节并将它们转换为 png 图像并将它们保存在项目的 /Images 文件夹中并通过标签显示它们。这些文件是在开发人员环境中创建和使用的,但一旦我发布它,只有文件会在 images 文件夹中创建,但不会被读取或显示在 IMG 标记中。

public string Image_Binary(string pic_id)
    {
        var imagepath=ConfigurationManager.AppSettings["ImagePath"];
        string picstring;
        string pid = pic_id;
        string path = imagepath+ pid + ".Png";
        if (pid != null && pid != "")
        {
             if (File.Exists(Server.MapPath(path)))
                {
                    picstring = imagepath + pid + ".Png";
                }

             else
             {

                 DataSet picds = DB.fetchdata("select PictureBinary FROM Picture where Id=" + pic_id);
                 byte[] picbin = (byte[])picds.Tables[0].Rows[0][0];
                 ImageConverter ic = new ImageConverter();
                 System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(picbin);
                 img.Save(Server.MapPath(imagepath + pid + ".Png"), System.Drawing.Imaging.ImageFormat.Png);
                 picstring = imagepath + pid + ".Png";




            }
        }
        else
        {
            //picstring = null;
            picstring = "#";
        }
        return picstring;
    }

Web.config 条目

  <appSettings>
  <add key="ImagePath" value="~/ProductImages/"
 </appSettings>

【问题讨论】:

  • 右击你的页面,点击检查元素并查看文件路径,你也应该在控制台出现404错误

标签: asp.net database image


【解决方案1】:

如果您的图像未存储在默认图像文件夹中,则发布后新文件夹将不包含在内。它不是代码错误。据我所知,代码是正确的。如果文件夹是在构建后创建的,请检查您的图像路径。

【讨论】:

  • 很久以前就解决了。但你对这个问题是对的。
猜你喜欢
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 2019-05-06
相关资源
最近更新 更多