引用图片路径,解决同一机器不同虚拟目录之间图片访问

问题:

1、同一台机器上部署了两个虚拟目标,A虚拟目录里对图片进行上传删除等操作,图片上传的位置在A虚拟目录中,例如:在AdvertisingImg文件夹中。

2、而B虚拟目录要求可以看到此图片。虽然是同一台机器,但直接用绝对路径查看图片是不行的。

解决方法:

http://localhost/A/AdvertisingImg/图片名称.后缀 

3、打开绝对路径图片:

  /// <summary>
        /// 下载JPG文件
        /// </summary>    
        /// <param name="strFileFullPath">文件绝对路径路径</param>
        /// <param name="page">下载的页面</param>
        /// <param name="strFileName">要保存的文件名</param>
        public static void DownloadLocalJpgFile(string strFileFullPath, System.Web.UI.Page page,string strFileName)
        {
            System.Web.HttpResponse response = page.Response;
            System.IO.FileInfo file = new System.IO.FileInfo(strFileFullPath);
            if (!file.Exists)
            {              
                return;
            }
            response.HeaderEncoding = System.Text.Encoding.GetEncoding("gb2312");
            response.Charset = "GB2312";
            response.Clear();
            response.Charset = "GB2312";
            response.ContentEncoding = System.Text.Encoding.UTF8;
            response.AddHeader("Content-Disposition", "attachment;filename=" + strFileName);
            response.AddHeader("Content-Length", file.Length.ToString());
            response.ContentType = "image/jpeg";
            response.WriteFile(file.FullName);
            response.End();
        }

原文地址:https://www.cnblogs.com/xbding/p/3245028.html