Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.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
C# 否';访问控制允许原点';对于特定大小的文件,角度文件上载时出现标头错误_C#_Asp.net_Angular_Asp.net Web Api - Fatal编程技术网

C# 否';访问控制允许原点';对于特定大小的文件,角度文件上载时出现标头错误

C# 否';访问控制允许原点';对于特定大小的文件,角度文件上载时出现标头错误,c#,asp.net,angular,asp.net-web-api,C#,Asp.net,Angular,Asp.net Web Api,我目前正在从一个角度前端上传一个文件到.NETWebAPI uploadFile(file: File, customerId: number) { var formData: FormData = new FormData(); formData.append('file', file, file.name); var headers = new HttpHeaders().set('Accept', 'application/json'); var options = { h

我目前正在从一个角度前端上传一个文件到.NETWebAPI

uploadFile(file: File, customerId: number) {
  var formData: FormData = new FormData();
  formData.append('file', file, file.name);
  var headers = new HttpHeaders().set('Accept', 'application/json');
  var options = { headers: headers, reportProgress: true };

  const req = new HttpRequest('POST', 'customers/' + customerId + '/fileupload', formData, options)
  return this.http.request(req);
} 
以及接收此帖子的Web API路由

[HttpPost]
[Route("{customerId}/fileUpload")]
public IHttpActionResult UploadFiles(int customerId)
{
    if (HttpContext.Current.Request.Files.Count > 0) 
    {
        _fileService.UploadFile(customerId, HttpContext.Current.Request.Files[0]);
        return Ok("Files Successfully Uploaded");
    } 
    else 
    {
        return Ok("0 Files Uploaded");
    }
}
当我发布一个3000万字节(~30mb)或更少的文件时,一切都按预期工作,但由于某些原因,当文件更大时,我得到错误:

POST http://localhost:53319/customers/116/fileupload/Production 404 (Not Found)
Failed to load http://localhost:53319/customers/116/fileupload/Production: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 404.
对于我的情况,我需要能够上传高达10Gbs的文件。有人知道为什么对于大于某个大小的文件会出现此错误,以及如何修复它吗

我已经对此做了一些研究,我所发现的只是在Web.config文件中添加了以下内容,但还没有解决这个问题

<system.web>
  <httpRuntime maxRequestLength="2147483647" />
</system.web>

请尝试这种web.config或至少是requestLimits部分。这来自.Net核心项目,因此语法可能会有所不同


默认值为30000000,约为28.6MB

我所需要的只是
部分。非常感谢。对于遇到此问题的任何其他人,
maxAllowedContentLength
的类型为
uint
,其最大值为4294967295。这意味着,在我的例子中,文件上传的最大值将是~4.29 GB。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="524288000"/>
        </requestFiltering>
    </security>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>