2012-07-09 64 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