Các s?n ph?m c?a bên th? ba đư?c th?o lu?n trong bài vi?t này đư?c s?n xu?t b?i
các công ty đ?c l?p c?a Microsoft. Microsoft đưa ra không có b?o hành,
ng? ? ho?c b?ng cách khác, liên quan đ?n hi?u su?t ho?c đ? tin c?y c?a các
s?n ph?m.
Khi b?n c? g?ng s? d?ng các Response.WriteFile phương pháp đ? t?i xu?ng m?t t?p tin l?n, t?i v? có th? đáp ?ng, và
sau đó, b?n có th? nh?n đư?c m?t trong các thông báo l?i sau đây:
Trang
không th? hi?n th?
- hay -
Server Application
Không s?n dùng
?ng d?ng Web b?n đang c? g?ng đ? truy c?p vào đây
Web server là hi?n không có s?n. H?y nh?n nút "Làm m?i" trong c?a b?n
Tr?nh duy?t web đ? th? l?i yêu c?u c?a b?n.
Qu?n tr? viên lưu ?: M?t l?i
thông báo chi ti?t các nguyên nhân c?a s? th?t b?i này yêu c?u c? th? có th? đư?c t?m th?y trong
vi?c ghi nh?t k? s? ki?n h? th?ng c?a máy ch? web. H?y xem l?i m?c nh?p Nh?t k? này đ?
khám phá nh?ng g? gây ra l?i này x?y ra.
B?n c?ng có th? nh?n các
thông báo sau trong s? ghi s? ki?n ?ng d?ng:
Aspnet_wp.exe
(ho?c W3wp.exe cho các ?ng d?ng ch?y trên Microsoft Internet Information Services [II] 6.0)
d?ng đ?t ng?t.
Trong quá tr?nh này, b?n c?ng có th? nh?n th?y m?t
tăng s? d?ng b? nh? c?a máy ch? Web.
C?u h?nh ph?n c?ng c?a máy tính máy ch? Web
xác đ?nh kích thư?c t?p t?i đa mà b?n có th? t?i xu?ng thành công. Khi các
ASP.Quá tr?nh công nhân NET (Aspnet_wp.exe ho?c W3wp.exe cho các ?ng d?ng ch?y trên Internet Information Services 6.0 [II])»
ch?y theo yêu c?u t?i v? t?p tin, t?p tin t?i v? h?p tho?i xu?t hi?n. Các
ASP.Quá tr?nh công nhân NET b?t đ?u g?i d? li?u đ?n Internet c?a Microsoft
Thông tin d?ch v? quá tr?nh (Inetinfo.exe hay Dllhost.exe). Nó không
ch? đ?i đ? b?n có th? nh?p vào Ok.
Tùy thu?c vào s?
c?u h?nh c?a máy tính, quá tr?nh IIS có th? x? l? d? li?u, ho?c các
d? li?u có th? đư?c buffered trong b? nh?. Khi các t?p tin l?n, các d? li?u đư?c buffered trong
b? nh? trong giao ti?p gi?a hai quá tr?nh. Đi?u này có th? gây ra m?t
tăng trong vi?c s? d?ng b? nh? trên h? ph?c v?. L?i x?y ra v?
gi?i h?n b? nh? trên máy ch? Web.
Đ? làm vi?c xung quanh v?n đ? này, h?y s? d?ng b?t k? m?t trong nh?ng đi?u sau đây
phương pháp:
Có đư?c các d? li?u trong ph?n nh?, và sau đó di chuy?n d? li?u
đ? d?ng su?i đ?u ra đ? t?i v?. Các m? sau đây ch?ng t? làm th? nào đ? làm đi?u
Đi?u này.
Quan tr?ng Khi b?n thi?t l?p giá tr? c?a các g? l?i thu?c tính c?a nguyên t? t?ng h?p đ? sai trong t?p tin Web.config ASP c?a b?n.?ng d?ng m?ng, b?n ph?i thi?t l?p các Server.ScriptTimeout b?t đ?ng s?n cho m?t giá tr? thích h?p cho kích thư?c t?i v? t?p tin. Theo m?c đ?nh, các Server.ScriptTimeout giá tr? đư?c thi?t l?p đ? 90 giây. Tuy nhiên, khi các g? l?i thu?c tính đư?c đ?t thành s? th?t, các Server.ScriptTimeout giá tr? s? đư?c đ?t r?t l?n 30,000,000 giây. Như là m?t nhà phát tri?n, b?n ph?i đư?c nh?n th?c c?a các tác đ?ng này có th? có trên hành vi c?a ASP c?a b?n.NET Web ?ng d?ng.
Ngoài ra, trong m? sau b?n ph?i đư?c nh?n th?c c?a các
các giá tr? tham s? đư?c s? d?ng v?i các FileStream nhà xây d?ng. Các giá tr? đ?m
r?ng đang làm specifed cho m?t tác đ?ng đáng k? v? các ch?c năng mà đư?c cung c?p. Cho
thêm thông tin, tham kh?o các FileStream liên k?t trong cácTÀI LIỆU THAM KHẢO keá tieáp. Th? giác
Cơ b?n.NET Code
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
Response.Close()
End Try
Visual C#.NET Code
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.
string filename = 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();
}
Response.Close();
}
Thay th? DownloadFileName v?i tên g?i c?a m?t
t?p tin l?n hơn 100 megabyte (MB).
- hay -
Cung c?p m?t liên k?t cho ngư?i dùng đ? t?i xu?ng các
t?p tin.
- hay -
S? d?ng Microsoft ASP 3.0 cho các t?i ho?c s? d?ng ph?n m?m
Ngh? nhân FileUp v?i ASP.
B?m đúp vào các đ?i tư?ng nút đ? m? các Nh?p vào s? ki?n trong Code View.
Dán m? sau đây trong Button1 Nh?p vào s? ki?n.
Visual Basic.NET Code
' 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/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)
Visual C#.NET Code
// 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);
Thay th? DownloadFileName v?i
tên t?p l?n hơn 100 MB.
QUAN TRỌNG: Bài vi?t này đư?c d?ch b?ng ph?n m?m d?ch máy c?a Microsoft ch? không ph?i do con ngư?i d?ch. Microsoft cung c?p các bài vi?t do con ngư?i d?ch và c? các bài vi?t do máy d?ch đ? b?n có th? truy c?p vào t?t c? các bài vi?t trong Cơ s? Ki?n th?c c?a chúng tôi b?ng ngôn ng? c?a b?n. Tuy nhiên, bài vi?t do máy d?ch không ph?i lúc nào c?ng hoàn h?o. Lo?i bài vi?t này có th? ch?a các sai sót v? t? v?ng, cú pháp ho?c ng? pháp, gi?ng như m?t ngư?i nư?c ngoài có th? m?c sai sót khi nói ngôn ng? c?a b?n. Microsoft không ch?u trách nhi?m v? b?t k? s? thi?u chính xác, sai sót ho?c thi?t h?i nào do vi?c d?ch sai n?i dung ho?c do ho?t đ?ng s? d?ng c?a khách hàng gây ra. Microsoft c?ng thư?ng xuyên c?p nh?t ph?n m?m d?ch máy này.
Nh?p chu?t vào đây đ? xem b?n ti?ng Anh c?a bài vi?t này:812406