2012-07-09 61 views
2

我正在使用uploadify v3.1 for MVC3 C#。MVC3 uploadify Jquery插件錯誤HTTP 404和IO錯誤

我CSHTML代碼

<div class="container_24"> 
    <input type="file" name="file_upload" id="file_upload" /> 
</div> 

我的js代碼是

$(document).ready(function() { 
    $('#file_upload').uploadify({ 
     'method': 'post', 
     'swf': '../../Scripts/uploadify-v3.1/uploadify.swf', 
     'uploader': 'DashBoard/UploadFile' 
    }); 
}); 

而控制器代碼是

[HttpPost] 
     public ActionResult UploadFile(HttpPostedFileBase file) 
     { 
      // Verify that the user selected a file 
      if (file != null && file.ContentLength > 0) 
      { 
       // extract only the fielname 
       var fileName = Path.GetFileName(file.FileName); 
       // store the file inside ~/App_Data/uploads folder 
       var path = Path.Combine(Server.MapPath("~/Uploads"), fileName); 
       file.SaveAs(path); 
      } 
      // redirect back to the index action to show the form once again 
      return RedirectToAction("Index", "Home"); 
     } 

現在,當我點擊上傳按鈕,它顯示了兩個錯誤,有時它顯示IO錯誤並且有時顯示HTTP 404某些文件錯誤。哪裏不對 ?請幫幫我 ?

+1

使用Asp.net MVC幫助程序生成路徑:''swf':'@(Url.Content(「〜/ Scripts/uploadify-v3.1/uploadify.swf」))', 'uploader' :'@(Url.Action(「DashBoard」,「UploadFile」))''。您還可以設置一個[onUploadError](http://www.uploadify.com/documentation/uploadify/onuploaderror/)來了解有關錯誤原因的更多信息。 – nemesv 2012-07-09 20:32:57

+0

謝謝你的評論,但你的想法是行不通的:(我應該現在不應該怎麼辦? – zxprince 2012-07-09 22:48:19

回答

7

上傳的文件大小是多少?一切超過1MB或其他任何東西?

另外什麼排序你404?如果它是404.13(文件大小錯誤),那麼你遇到了同樣的問題。好消息。因爲我解決了我的問題。 :)

如果你不知道什麼類型的404(螢火蟲會告訴你),檢查你的Windows事件日誌,並期待在「應用程序」日誌,看起來像這樣的警告:

  • 事件代碼:3004
  • 事件消息:郵政大小超出允許限制。

如果你有這兩個,那麼問題是IIS(我假設你使用的)沒有設置爲允許足夠大的內容請求。

首先,把這個在你的web配置:

<system.webServer> 
    <security> 
     <requestFiltering> 
     <!-- maxAllowedContentLength = bytes --> 
     <requestLimits maxAllowedContentLength="100000000" /> 
     </requestFiltering> 
    </security> 
    </system.webServer> 

然後這一點,在 「System.Web程序」:

<!-- maxRequestLength = kilobytes. this value should be smaller than maxAllowedContentLength for the sake of error capture -->  
<httpRuntime maxRequestLength="153600" executionTimeout="900" /> 

請注意提供的筆記 - maxAllowedContentLength是BYTES和maxRequestLength KILOBYTES - 差別很大。

我提供的maxAllowedContentLength值可以讓你加載任何高達95MB左右的東西。

無論如何,這解決了我的這個問題的版本。

+0

我遇到與OP所述相同的問題,此解決方案無法解決我的問題,有沒有其他方法可以解決此問題? – 2015-12-09 06:53:05