?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

澳門星際手機版官方下載:Response.WriteFile無法下載大文件

?

當您考試測驗應用 response.writefile 措施下載大年夜文件時,下載操作可能沒有相應,并且隨后可能會收到以下差錯信息之一:

The page cannot be displayed- 或 -

Server Application Unavailable

The Web application you are attempting to access on this Web server is currently unavailable.Please hit the "Refresh" button in your Web browser to retry your request.

Administrator Note:An error message detailing the cause of this specific request failure can be found in the system event log of the web server.Please review this log entry to discover what caused this error to occur.您還可能會在利用法度榜樣事故日志中看到以下消息:

Aspnet_wp.exe(對付在 Microsoft Internet 信息辦事 [IIS] 6.0 上運行的利用法度榜樣,則為 W3wp.exe)意外竣事。

在此歷程中,您還可能會發明 Web 辦事器的內存應用量增添。

回到頂端

緣故原由

Web 辦事器謀略機的硬件設置設置設備擺設擺設抉擇您可以成功下載的最大年夜文件大年夜小。當 ASP.NET 幫助進程(Aspnet_wp.exe,對付在 Internet 信息辦事 6.0 [IIS] 上運行的利用法度榜樣,則為 W3wp.exe)履行文件下載哀求時,會呈現文件下載對話框。ASP.NET 幫助進程開始向 Microsoft Internet 信息辦事進程(Inetinfo.exe 或 Dllhost.exe)發送數據。它不等您單擊“確定”即開始發送。

根據謀略機的設置設置設備擺設擺設,IIS 進程可能會處置懲罰數澳門星際手機版官方下載據,也可能會將數據緩存在內存中。假如文件太大年夜,在這兩個進程互相通信的歷程中,數據將被緩存在內存中。這可能會導致辦事器上的內存應用量增添。呈現此差錯的緣故原由是 Web 辦事器上的內存限定。

回到頂端

替代措施

要辦理此問題,請應用以下任一措施: 將數據分成較小的部分,然后將其移動到輸出流以供下載,從而獲取這些數據。以下代碼演示了若何完成此操作。

緊張闡明:當您在 ASP.NET 利用法度榜樣的 Web.config 文件中將編譯元素的 debug 屬性值設置為 false 時,必須針對要下載的文件大年夜小將 server.scripttimeout 屬性設置為適當的值。默認環境下,server.scripttimeout 值被設置為 90 秒。然則,當 debug 屬性被設置為 true 時,server.scripttimeout 值將被設置為一個異常大年夜的值(30,000,000 秒)。作為一名開拓職員,您必須知道這可能會對您的 ASP.NET Web 利用法度榜樣的行徑造成的影響。

此外,鄙人面的代碼中,您還必須知道與 filestream 構造函數一路應用的參數值。指定的羅列值會對供給的功能孕育發生重大年夜影響。有關更多信息,請參考 參考 一節中的 fi澳門星際手機版官方下載lestream 鏈接。

visual Basic .NET 代碼

Dim iStream As System.IO.Stream

' Buffer to read 10K bytes in chunk:

Dim buffer(10000) As Byte

' Length of the file澳門星際手機版官方下載:

Dim length As Integer

' Total bytes to read:

Dim dataToRead As Long

' Identify the file to download including its path.

Dim filepath As String = "DownloadFileName"

' Identify the file name.

Dim filename As String = System.IO.Path.GetFileName(filepath)

Try

' Open the file.

iStream = New System.IO.FileStream(filepath, System.IO.FileMode.Open, _

IO.FileAccess.Read, IO.FileShare.Read)

' Total bytes to read:

dataToRead = iStream.Length

Response.ContentType = "application/octet-stream"

Response.AddHeader("Content-Disposition", "attachment; filename=" & filename)

' Read the bytes.

While dataToRead > 0

' Verify that the client is connected.

If Response.IsClientConnected Then

' Read the data in buffer

length = iStream.Read(buffer, 0, 10000)

' Write the data to the current output stream.

Response.OutputStream.Write(buffer, 0, length)

' Flush the data to the HTML output.

Response.Flush()

ReDim buffer(10000) ' Clear the buffer

dataToRead = dataToRead - length

Else

'prevent infinite loop if user disconnects

dataToRead = -1

End If

End While

Catch ex As Exception

' Trap the error, if any.

Response.Write("Error : " & ex.Message)

Finally

If IsNothing(iStream) = False Then

' Close the file.

iStream.Close()

End If

End Try

Visual C# .NET 代碼

System.IO.Stream iStream = null;

// Buffer to read 10K bytes in chunk:

byte[] buffer = new Byte[10000];

// Length of the file:

int length;

// Total bytes to read:

long dataToRead;

// Identify the file to download including its path.

string filepath= "DownloadFileName";

// Identify the file name.

stringfilename= System.IO.Path.GetFileName(filepath);

try

{

// Open the file.

iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,

System.IO.FileAccess.Read,System.IO.FileShare.Read);

// Total bytes to read:

dataToRead = iStream.Length;

Response.ContentType = "application/octet-stream";

Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

// Read the bytes.

while (dataToRead > 0)

{

// Verify that the client is connected.

if (Response.IsClientConnected)

{

// Read the data in buffer.

length = iStream.Read(buffer, 0, 10000);

// Write the data to the current output stream.

Response.OutputStream.Write(buffer, 0, length);

// Flush the data to the HTML output.

Response.Flush();

buffer= new Byte[10000];

dataToRead = dataToRead - length;

}

else

{

//prevent infinite loop if user disconnects

dataToRead = -1;

}

}

}

catch (Exception ex)

{

// Trap the error, if any.

Response.Write("Error : " + ex.Message);

}

finally

{

if (iStream != null)

{

//Close the file.

iStream.Close();

}

}

將 DownloadFileName 調換為大年夜于 100 MB 的文件的名稱。

- 或 -

為用戶供給用于下載文件的鏈接。

- 或 -

應用 Microsoft ASP 3.0 進行下載或者與 ASP 一路應用 Software Artisans FileUp。

- 或 -

創建 ISAPI 擴展以下載文件。

- 或 -

應用 FTP 下載文件。

回到頂端

狀態

這種征象是設計導致的。

回到頂端

更多信息

重現此問題的步驟

1.

在 Microsoft Visual Basic .NET 或 Microsoft Visual C# .NET 中,新建一個 Web 利用法度榜樣項目。默認環境下,將創建 WebForm1.aspx。

2.

將一個按鈕工具從對象箱拖到 WebForm1.aspx。

3.

雙擊該按鈕工具以便在代碼視圖中打開 click 事故。

4.

將以下代碼粘貼到 Button1 click 事故中。

visual Basic .NET 代碼

' Identify the file to download including its path.

Dim filepath As String = DownloadFileName

' Identify the file name.

Dim filename As String = System.IO.Path.GetFileName(filepath)

Response.Clear()

' Specify the Type of the downloadable file.

Response.ContentType = "application/o澳門星際手機版官方下載ctet-stream"

' Set the Default file name in the FileDownload dialog box.

Response.AddHeader("Content-Disposition", "attachment; filename=""" & filename & """")

Response.Flush()

' Download the file.

Response.WriteFile(filepath)

Visual C# .NET 代碼

// Identify the file to download including its path.

string filepath = DownloadFileName;

// Identify the file name.

string filename = System.IO.Path.GetFileName(filepath);

Response.Clear();

// Specify the Type of the downloadable file.

Response.ContentType = "application/octet-stream";

// Set the Default file name in the FileDownload dialog box.

Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

Response.Flush();

// Download the file.

Response.WriteFile(澳門星際手機版官方下載filepath);

5.

將 DownloadFileName 調換為大年夜于 100 MB 的文件的名稱。

6.

在“調試”菜單上,單擊“開始”。

7.

單擊“Button1”

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

快三平台开户