Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ASP.NET webAPI上载文件(最大10Mb文件大小)_Asp.net_Asp.net Mvc_Asp.net Web Api - Fatal编程技术网

使用ASP.NET webAPI上载文件(最大10Mb文件大小)

使用ASP.NET webAPI上载文件(最大10Mb文件大小),asp.net,asp.net-mvc,asp.net-web-api,Asp.net,Asp.net Mvc,Asp.net Web Api,我在一个包含Web API控制器的VS2012 MVC4项目上工作。此项目将在IIS服务器上发布 我需要允许用户上传文件。问题在于,web API的最大上传文件大小限制为4MB。我读到(例如这里:)我们可以通过自托管web API(在本例中,文件上传高达2GB)来扩展这一限制。我不想自己托管我的webAPI,因为我想在我的IIS web服务器上托管它,所以我认为这不适合我的情况,对吗?那么,上传大于4MB的文件我能做些什么呢 如果可能的话,我会搜索HTML5解决方案(拖放) 到目前为止,我找到的

我在一个包含Web API控制器的VS2012 MVC4项目上工作。此项目将在IIS服务器上发布

我需要允许用户上传文件。问题在于,web API的最大上传文件大小限制为4MB。我读到(例如这里:)我们可以通过自托管web API(在本例中,文件上传高达2GB)来扩展这一限制。我不想自己托管我的webAPI,因为我想在我的IIS web服务器上托管它,所以我认为这不适合我的情况,对吗?那么,上传大于4MB的文件我能做些什么呢

如果可能的话,我会搜索HTML5解决方案(拖放)

到目前为止,我找到的任何解决方案都不允许我实现这一目标


感谢您的帮助。

如果您仔细阅读,它会说“ASP.NET在您可以上载的文件大小方面的最大限制为2G”。因此,基本上,当托管在ASP.NET/IIS中时,您将能够接收高达2GB的文件。您需要做的是更改web.config中的一些默认值


请检查:

可能不清楚,但实际上博客URL指的是IIS。您需要在Web.config中查找以下2个设置以增加上载大小:

注意
maxRequestLength
以KB为单位:

<system.web>
  <httpRuntime targetFramework="4.5" maxQueryStringLength="" maxRequestLength="" maxUrlLength="" />

您可以检查此项

 int MaxContentLength = 1024 * 1024 * 10; //Size = 10 MB
if (postedFile.ContentLength > MaxContentLength)
{


}

非常感谢您提供此信息。另请参阅有关处理超大上传的链接:
 int MaxContentLength = 1024 * 1024 * 10; //Size = 10 MB
if (postedFile.ContentLength > MaxContentLength)
{


}