我的ASP.NET程序,在一个页面中用第三方控件显示TIF格式的图片,程序根据图片的级别确定页面上的一个超链接是否可用,当可用时,允许用户点击此链接下载,但这个超链接暴露了图片所在的地址及目录,使得用户可在地址栏中输入链接就可下载,
怎么能允许下载文件又不显示出地址呢?

解决方案 »

  1.   

    1、在 IIS 中,把存放文件的目录的读取选项去掉
    2、使用下列代码进行下载
    string path = Server.MapPath("../Downlaod/"+Session["FileUrl"] as string);
    if(!System.IO.File.Exists(path )){return;}
    FileInfo file = new System.IO.FileInfo(path); 
    Response.Clear(); 
    Response.Charset="GB2312"; 
    Response.ContentEncoding=System.Text.Encoding.UTF8; 
    Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); 
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/ms-excel"; 
    Response.WriteFile(path);
    Response.End();
      

  2.   

    Response.TransmitFile(Server.MapPath("/Upload/2006112701010.rar"));这个比Response.WriteFile()好。