을 주셔서 감사합니다. 이러한 방법을 사용하지 않고 할 수있는 최선의 방법은 web.config 파일에 maxRequestLength
을 설정하는 것입니다.
예 :
<system.web>
<httpRuntime maxRequestLength="1024"/>
위 예 1메가바이트에 대한 파일 크기를 제한한다. 사용자가 더 큰 것을 보내려고하면 최대 요청 길이를 초과했다는 오류 메시지가 표시됩니다. 그래도 예쁜 메시지는 아니지만 원하는 경우 IIS의 오류 페이지를 무시하여 사이트와 일치시킬 수 있습니다. DUE
편집 댓글에 :
그래서 아마 그래서이 개 가능한 솔루션을 게시 할 예정 URL에서 파일을 얻을 수있는 요청을 수행하는 방법의 몇 가지를 사용하여. 먼저 .NET WebClient
을 사용하고 있습니다 :
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://www.somewhere.com/test.txt"));
webRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
if (fileSize < iMaxNumberOfBytesToAllow)
{
// Download the file
}
희망 이러한 솔루션 중 하나 돕거나 : 다른 방법은 바로 파일 크기를 확인하기 위해 다운로드를하기 전에 기본적인 웹 요청을 할 수 있었다
// This will get the file
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(DownloadCompleted);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
webClient.DownloadFileAsync(new Uri("http://www.somewhere.com/test.txt"), @"c:\test.txt");
private void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
WebClient webClient = (WebClient)(sender);
// Cancel download if we are going to download more than we allow
if (e.TotalBytesToReceive > iMaxNumberOfBytesToAllow)
{
webClient.CancelAsync();
}
}
private void DownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
// Do something
}
최소한 올바른 방향으로 가십시오.
bytesTotal
이 제한
최대 다운로드 또는 최대 업로드 내에있는 경우 – Aristos
@Aristos - 최대 다운로드에 대해 이야기하고 있습니다. My asp .net 페이지는 전달 된 URL을 다운로드합니다. –