2011-09-29 62 views
0

這是我的代碼上傳視頻服務器C#上傳失敗的視頻

protected void Button1_Click(object sender, EventArgs e) 
{ 
    if (FileUpload1.HasFile) 
    { 
     string fileName = FileUpload1.FileName; 
     string fileExtension = Path.GetExtension(fileName); 

     if (fileExtension == ".flv") 
     { 
      if (!File.Exists(Path.Combine(Server.MapPath("~/Video"), fileName))) 
      { 
       string fullFileName = Path.Combine(Server.MapPath("~/Video1"), fileName); 
       FileUpload1.SaveAs(fullFileName); 
       Label1.Text = "The file has been uploaded"; 

      } 
      else 
      { 
       Label1.Text = "The file already exist! You must delete old version first in order to upload new version"; 
      } 

     } 
     else 
     { 
      Label1.Text = "The file format is not allow"; 
     } 

    }//else if 
    else 
    { 
     Label1.Text = "please select a file to upload"; 
    } 

} 

一切都順利,但是當我上傳.FLV文件,它返回我的網頁上的錯誤信息,這裏是錯誤代碼

輸出:錯誤101(net :: ERR_CONNECTION_RESET):連接重置爲 。

我該如何解決這個問題?

回答

1

也許您正在嘗試上傳大於4MB的文件,這是默認的最大allowed size。您可以嘗試在web.config增加它:

<system.web> 
    <!-- Set the maximum upload file size to 100MB --> 
    <httpRuntime executionTimeout="240" maxRequestLength="102400" /> 
</system.web> 
1

一般情況下,我將下面的代碼到我的項目..

<system.web> 
     <httpRuntime maxRequestLength="102000" executionTimeout="110"/> 
    </system.web> 

但是,如果你不是延長...

4MB的默認值是在machine.config中設置,但你可以在你的web.config中覆蓋它。例如,要將上傳限制擴大到20MB,您應該這樣做:

<system.web> 
    <httpRuntime executionTimeout="240" maxRequestLength="20480" /> 
</system.web