解决方案 »

  1.   

    这个是显示图片,因为浏览器认识png的格式,自动做显示处理了你需要后台写一个输出二进制格式图片文件流,并且指定
    contenttype为
    <meta http-equiv="Content-Disposition" content="attachment;">
      

  2.   

    如果是你自己的站点
    通过 IHttpModule 
            /// <summary>
            /// 在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生(4.5、4、3.5、3.0、2.0、1.1、1.0)。
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void PostRequestHandlerExecuteEvent(object sender, EventArgs e)
            {
                HttpApplication ha = (HttpApplication)sender;            string filePath = ha.Request.FilePath;            if (filePath.Contains(".") && filePath.Remove(0, filePath.LastIndexOf('.')) == ".png")
                {
                    using (FileStream fs = new FileStream(ha.Server.MapPath(filePath), FileMode.Open, FileAccess.Read))
                    {
                        int fslength = (int)fs.Length;
                        byte[] b = new byte[fslength];
                        fs.Read(b, 0, fslength);
                        ha.Response.ContentType = "application/octet-stream";
                        ha.Response.Write(b);
                        ha.Response.Flush();
                        ha.Response.End();
                    }
                }
            }<html>
    <head>
    </head>
    <body>
    <img src="http://stimgcn1.s-msn.com/msnportal/hp/2012/10/18/b24b7623-cddc-408d-a01a-c6c3582a612b.png" />
    <a target="_blank" href="http://stimgcn1.s-msn.com/msnportal/hp/2012/10/18/b24b7623-cddc-408d-a01a-c6c3582a612b.png" >测试图片下载!</a>
    </body>
    </html>
      

  3.   

    如果你用 IHttpModule 那是不是可以在 web.config中配置那。
      

  4.   


    /// <summary>
        /// 文件下载
        /// </summary>
        /// <param name="s_fileName"></param>
        public static void downloadfile(string s_fileName)
        {
            HttpContext.Current.Response.ContentType = "application/ms-download";
            string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName;
            System.IO.FileInfo file = new System.IO.FileInfo(s_path);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
            HttpContext.Current.Response.Charset = "utf-8";
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
            HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
            HttpContext.Current.Response.WriteFile(file.FullName);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.End();
        }后台onclick调用就行了.
      

  5.   

    不用,C# 的, C# 的 代码满天飞。我的意思是直接加  http-equiv 的方式
      

  6.   

    refer : http://blog.csdn.net/awinliu/article/details/9401083
      

  7.   

    大神们,问下,我把<meta http-equiv="Content-Disposition" content="attachment;">  这句放在前台,后台写的如下
                result += @"<ul>
                                    <li style='width:400px;' >
                                    <a target='_blank' href='../upload/UserInfo/" + inside.Inside_number + @"/" + name + @"/" + info.Name + @"'" + @">" + info.Name + @"</li>
                                     <li style='width:117px;'> 
                                    <a target='_blank' href='../upload/UserInfo/" + inside.Inside_number + @"/" + name + "/" + info.Name + "'" + @">下载</a>" + @"</li>
    这样下载图片还是不行啊,那这样应该如何做啊?