VB.net没有提示用户下载使用Response.Flush

我试图让用户使用工作簿/工作表对象下载在VB.net中创build的Excel文件。 excel文件的创build完成,但下一个是允许用户下载它,当他们点击一个button。 我已经使用Response编码了我所期望的方法,但是当我单击button时,下载事件(在Chrome / IE上testing)不会发生。 就好像我从来没有按下button,但它在debugging过程中通过代码运行。

Protected Sub btnMatrixSummary_Click(sender As Object, e As System.EventArgs) Handles btnMatrixSummary.Click Dim refNum As Integer = employee_LB.SelectedValue Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application() Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet Dim misValue As Object = System.Reflection.Missing.Value xlWorkBook = xlApp.Workbooks.Add(misValue) xlWorkSheet = xlWorkBook.Sheets("sheet1") xlWorkSheet.Cells(1, 2) = "1. Displays High Integrity & Honesty" '----------FILL REST OF EXCEL FILE HERE--------------------- 'Prepare download file Dim folder As String = Path.GetTempPath xlWorkBook.SaveAs(folder & "Matrix.xlsx") Dim filePath As System.IO.FileInfo = New System.IO.FileInfo(xlWorkBook.FullName) xlWorkBook.Close(True, misValue, misValue) xlApp.Quit() releaseObject(xlWorkSheet) releaseObject(xlWorkBook) releaseObject(xlApp) Response.ClearHeaders() Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=Matrix6.xls") Response.AddHeader("Content-Length", filePath.Length.ToString()) Response.ContentType = "application/vnd.xls" Response.WriteFile(filePath.FullName) HttpContext.Current.Response.Flush() 'Sends all currently buffered output To the client. HttpContext.Current.Response.SuppressContent = True 'Gets Or sets a value indicating whether To send HTTP content To the client. HttpContext.Current.ApplicationInstance.CompleteRequest() 'Delete local matrix off server My.Computer.FileSystem.DeleteFile(filePath.FullName)