asp.net网站上传到空间后,.exe 下载不了,但是.doc的却可以下载成功
这是怎么回事???

解决方案 »

  1.   

    用流输出来下载            DataSet ds = db.GetDataSet(query, new string[] { "@id" }, new object[] { DNTRequest.GetInt("id", 0) });
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    db.ExecuteUpdate("Update GL_Files Set hits=hits + 1 Where id=@id", new string[] { "@id" }, new object[] { DNTRequest.GetInt("id", 0) });
                    string url = ds.Tables[0].Rows[0]["url"].ToString();
                    string filename = ds.Tables[0].Rows[0]["FileTitle"].ToString() + "." + ds.Tables[0].Rows[0]["FileExt"].ToString();
                    using (FileStream fso = new FileStream(Server.MapPath(url), FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        int len = Convert.ToInt32(fso.Length);
                        byte[] FileObj = new byte[len];
                        fso.Read(FileObj, 0, len);
                        Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(filename), System.Text.Encoding.UTF8));
                        Response.AddHeader("Content-Length", len.ToString());
                        Response.ContentType = "application/octet-stream";
                        Response.Charset = "UTF-8";
                        Response.ContentEncoding = System.Text.Encoding.UTF8;
                        Response.BinaryWrite(FileObj);
                        Response.Flush();
                        Response.Clear();
                        fso.Close();
                    }
                }
      

  2.   


    #region 二进制下载
    private void FN_ResponseFile()
    {
    string id = Request["id"].ToString();//获取资源的编号
    System.IO.Stream iStream = null;
    byte[] buffer = new Byte[10000];
    int length;
    long dataToRead;
    NRBLL.File bf = new Asiastar.NRBLL.File();
    Guid guid = new Guid(id);
    if (bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"] != null)//判断数据库路径是否存在
    {
    string filepath = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"].ToString();//获取资源完整路径
    string filename = System.IO.Path.GetFileName(filepath);//获取资源名称 try
    {
    string fileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(filename));//解码(注意这里2层解码)
    filename = filename.Replace("+", "%20");  //将“+”替换成“空格”
    iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
    dataToRead = iStream.Length;
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
    while (dataToRead > 0)
    {
    if (Response.IsClientConnected)
    {
    length = iStream.Read(buffer, 0, 10000);
    Response.OutputStream.Write(buffer, 0, length); Response.Flush();
    buffer = new Byte[10000];
    dataToRead = dataToRead - length;
    }
    else
    {
    dataToRead = -1;
    }
    } }
    catch (Exception)
    {
    Response.Write("找不到该文件!");
    }
    finally
    {
    if (iStream != null)
    {
    iStream.Close();
    }
    }
    }
    else
    {
    Response.Write("找不到该文件!");
    }
    }
    #endregion你数据库保存的是不是完整路径 如果是用我这个
      

  3.   

    记得想让下载.exe是需要配置IIS的
      

  4.   

    是服务器设置的问题吧。exe文件,很危险。。
      

  5.   

    感谢是服务器配置的问题,可能是服务器安装了MAF
      

  6.   

    还是没解决!.exe,.rar,.zip格式都不能下载,但.doc,.txt可以下载,怎么解决,望高人快出手啊!
      

  7.   

    function IMG1_onclick() {
        public void DownLoad( )
    {
         string filePath = Server.MapPath( @"\hmj_360.zip");//这里注意了,你得指明要下载文件的路径.     if ( System.IO.File.Exists( filePath ) )
         {
              FileInfo file = new FileInfo( filePath );
              Response.ContentEncoding = System.Text.Encoding.GetEncoding( "UTF-8" ); //解决中文乱码
          Response.AddHeader( "Content-Disposition", "attachment; filename=" + Server.UrlEncode( file.Name ) ); //解决中文文件名乱码    
          Response.AddHeader( "Content-length", file.Length.ToString() );
              Response.ContentType = "appliction/octet-stream";
              Response.WriteFile( file.FullName );
              Response.End();
              }
    }
    这是我的类
      

  8.   

    <div class="foot1"><img src="images/foot2.gif" border="0" usemap="#Map" id="IMG1" />
    <map name="Map" id="Map"><area shape="rect" coords="818,156,925,214" href="hmj_360.zip"/>
    </map></div>    这是我的调用!
      

  9.   


    支持这个,应该是IIS里面的MINE没有配置好