在ASHX中返回ZipFile

时间:2016-12-23 10:46:56

标签: asp.net vb.net ashx

我有一个ASHX文件,它接收一些参数(用户和密码)。使用此参数我需要发送一个zipfile作为ASHX的结果。我已经编写了这段代码,但是当我打开下载的zip时,它似乎已损坏。

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

    context.Response.Clear()

    context.Response.ContentType = "application/x-zip-compressed"



    Dim sLoginName As String = context.Request.QueryString("LOGIN_NAME")
    Dim sLoginPassword As String = context.Request.QueryString("LOGIN_PASSWORD")

    If (Not String.IsNullOrEmpty(sLoginName) And
        Not String.IsNullOrEmpty(sLoginPassword)) Then

        If (CheckLogin(sLoginName, sLoginPassword)) Then



            Dim sZipUpdatePath As String = String.Empty

            Dim sVersionToInstall As String = GetVersionToInstall(sLoginName, sLoginPassword)
            Dim sZipName As String = "UPDATE.zip"

            If (Not String.IsNullOrEmpty(sVersionToInstall) And
                Not String.IsNullOrEmpty(sZipName)) Then

                sZipUpdatePath = "~\Updates\" + sVersionToInstall + "\" + sZipName



                context.Response.TransmitFile(context.Server.MapPath(sZipName))


            End If

        End If

    End If

End Sub

如何解决?

0 个答案:

没有答案