检查IIS的MIME类型定义中是否包含*.zip类型

解决方案 »

  1.   

    请关注我的问题
    http://expert.csdn.net/Expert/topic/2264/2264082.xml?temp=9.945095E-03
      

  2.   

    不应该是IIs设置不对吧,因为response.Redirect(http://localhost/download/aaa.htm)等,只要跳转的是目的文件是.htm,.asp,.aspx,.html等网页文件类型就可以了,而只要是.mp3,.rm,.dat,.zip等类型就不能实现文件下载。是不是因为response.Redirect只对网页文件有用,而无法完成文件下载功能吧,如果实现的是下载功能,那常用的方法是什么呢?还有qimini(循序渐进)大侠所说的MIME类型太深奥了,不知道是什么东西,我在IIs里找了很久都没找到。
      

  3.   

    你把文件读到一个流对象里,然后向客户端输出这个流
    System.IO.FileInfo myFileInfo = new System.IO.FileInfo(sfileFullName.ToString());
    Response.Buffer=true;
    Response.Clear();
    Response.ContentType = "application/vnd.ms-word";
    Response.AddHeader("Content-Disposition","attachment; filename="+HttpUtility.UrlEncode(sfileName,System.Text.Encoding.UTF8));
    Response.AddHeader("Content-Length",myFileInfo.Length.ToString());
    Response.WriteFile(sfileFullName.ToString());
    Response.End();
      

  4.   

    Response.Write("<script>location.href='http://localhost/download/aaa.zip';</script>');
      

  5.   

    ==aoyo(遨游)
    试了你那种方法还是不行呀。
    ==guoyan19811021(吉祥),asam2183(三山),qimini(循序渐进) 
    关于你们对iis设置的解释我一直都很迷茫,能不能具体的谈一下呢。
      

  6.   

    ==cnhgj(戏子?我菜,故我在)
    你的方法可行!!,不过遇到象.vb,.config,.resx,.cs等VisualStudio文件就会出现提示如下:
    无法提供此类型的页。 
    说明: 由于已明确禁止所请求的页类型,无法对该类型的页提供服务。扩展名“.vb”可能不正确。 请检查以下的 URL 并确保其拼写正确。
      

  7.   

    <a href='http://localhost/download/aaa.zip'>下载吧</a>
      

  8.   

    .vb,.config,.resx,.cs
    好像是禁止下栽的
      

  9.   

    to==guoyan19811021(吉祥),asam2183(三山),qimini(循序渐进)
    求教iis设置
      

  10.   

    Use HttpHandler can solve the problem. I made a link something like this:<a href="http://www.domain.com/downloadhandler.aspx?id=10>Download</a>downloadhandler.aspx is a httphandler here, it will get the correspondent file according to the id. In fact this is the approach to make a secure download for digital goods, it is very useful in e-Commence if you are selling digital good online.
      

  11.   

    to  laochen(天行者) :
    can you share the source code of downloadhandler.aspx to us?
      

  12.   

    to laochen(天行者) :
    can you share the source code of downloadhandler.aspx to us?
      

  13.   

    to  laochen(天行者) 
    yes, i had trying this way just as it was,but what can we do if the id's value is the file such as .vb,.cs,.config,.resx.  this problem just is my problem,not the way how to make a link
      

  14.   

    To All the friends here,The following is the HttpHandler I made for my freind's web site, it is working for both .zip and .exe files. I did not try on .vb, .cs, .config and .resx, but I believe it will work also as I feed file as "application/octet-stream". The code is in VB.NET, but I believe u guys should not be any problem on understanding.In order to use my code, u need modify your web.config accordingly.<configuration>
      <system.web>
        ......    <httpHandlers>
          <add verb="*" path="download.aspx" type="TheBooksWeb.DownloadHandler,TheBooksWeb"/>
        </httpHandlers>    .......  </system.web>
      ........
    </configuration>There is no need to construct a "download.aspx" file in this case.This is a sample download link I create, I send this link to my client in email.<A href="http://mydomain.com/utility/download.aspx?productid=10&token=3D2b12e304-3872-458e-a824-866677b1ccf8">Self-Made Millionaires</A>Imports System.Web
    Imports System.IO
    Imports System.Data.OleDbPublic Class DownloadHandler
        Implements IHttpHandler    Private _strConn As String    ' Override the ProcessRequest method.
        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
            Dim fPath As String = ConfigurationSettings.AppSettings("fPath")
            Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & fPath & "\db.mdb"
            Dim ProductId As String = context.Request.Params("productid")
            Dim Token As String = context.Request.Params("token")        ' Create Instance of Connection and Command Object
            Dim myConnection As OleDbConnection = New OleDbConnection(strConn)
            Dim strSQL As String = "SELECT tokens.token, tokens.expire, tokens.productid, products.filename, categories.category " & _
            "FROM (tokens INNER JOIN products ON tokens.productid = products.id) INNER JOIN categories ON products.categoryid = categories.id " & _
            "WHERE productid=" & ProductId & " AND token='" & Token & "'"        Try
                Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
                myConnection.Open()
                Dim result As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
                If result.Read Then
                    If result.Item("productid") = ProductId And result.Item("token") = Token Then
                        Dim Expire As DateTime = result.Item("expire")
                        Dim fLength As Long
                        Dim Filename As String                    If DateTime.Compare(Expire, Now()) >= 0 Then
                            Filename = fPath & "\books\" & result.Item("category") & "\" & result.Item("filename")
                            
                            Dim fi As FileInfo = New FileInfo(Filename)
                            fLength = fi.Length                        context.Response.ContentType = "application/octet-stream"
                            context.Response.AppendHeader("Content-Disposition", "attachment; filename=" & System.IO.Path.GetFileName(Filename))
                            context.Response.AddHeader("Content-Length", fLength.ToString())
                            context.Response.WriteFile(Filename)
                        Else
                            Throw New Exception("Your link had been expired.")
                        End If
                    Else
                        Throw New Exception("Either productid or token is invalid.")
                    End If
                Else
                    Throw New Exception("Either productid or token is invalid.")
                End If
            Catch ex As Exception
                context.Response.ContentType = "Text/HTML"
                context.Response.Write("<H1>Invalid Download Link</H1>")
                context.Response.Write("<H3>ProductId: " & ProductId & "</H3>")
                context.Response.Write("<H3>Token: " & Token & "</H3>")
                context.Response.Write("<H3>Reason:" & ex.Message & "</H3>")
                Return
            Finally
                myConnection.Close()
            End Try
        End Sub    ' Override the IsReusable property.        
        Public ReadOnly Property IsReusable() As Boolean _
        Implements IHttpHandler.IsReusable
            Get
                Return True
            End Get
        End PropertyEnd Class
      

  15.   

    Continue:My file downloader is quite helpful, u can modify it accordingly and apply your own function, for instance, you can craete a download counter in your database before feeding files to the user.Cheers
      

  16.   

    To ddmor(ddmor),I confirm my method works as I did test on ".vb" extension name. You may try the link below. It will feed you a file, namely as "test.vb".http://202.126.180.73\utility\download.aspx?productid=11&token=supertoken