2

こことGoogleでこれに対する答えを検索しようとしましたが、まだ見つけていません。私は、Web API サービスへの .NET 4.0 アップロードにかなり標準的であることがわかったものを使用しています。コードは次のとおりです。

    public HttpResponseMessage Post()
    {
        if (!Request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }
        StringBuilder sb = new StringBuilder();

        string root = HttpContext.Current.Server.MapPath("~/App_Data");
        var provider = new MyMultipartFormDataStreamProvider(root);

        var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith<HttpResponseMessage>(t =>
        {
            if (t.IsFaulted || t.IsCanceled)
            {
                Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
            }

            // This will give me the form field data
            foreach (var key in provider.FormData.AllKeys)
            {
                foreach (var val in provider.FormData.GetValues(key))
                {
                    sb.Append(string.Format("{0}: {1}", key, val));
                }
            }

            // This will give me any file upload data
            foreach (MultipartFileData file in provider.FileData)
            {
                sb.Append(file.Headers.ContentDisposition.FileName);
                sb.Append("Server file path: " + file.LocalFileName);
            }
            return new HttpResponseMessage()
            {
                Content = new StringContent(sb.ToString())
            };
        });
        return Request.CreateResponse(HttpStatusCode.OK);
    }

input type=file で非常に基本的なフォームを作成して送信すると、約 800Kb を超えるファイルに対して例外がスローされます。例外は次のとおりです。

System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=Value does not fall within the expected range.
  Source=mscorlib
  StackTrace:
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress()
       at System.Web.HttpWorkerRequest.IsLocal()
       at System.Web.Configuration.CustomErrorsSection.CustomErrorsEnabled(HttpRequest request)
       at System.Web.HttpContextWrapper.get_IsCustomErrorEnabled()
       at System.Web.Http.WebHost.HttpControllerHandler.<>c__DisplayClassa.<ConvertRequest>b__9()
       at System.Lazy`1.CreateValue()
       at System.Lazy`1.LazyInitValue()
       at System.Lazy`1.get_Value()
       at System.Web.Http.HttpConfiguration.ShouldIncludeErrorDetail(HttpRequestMessage request)
       at System.Net.Http.HttpRequestMessageExtensions.CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Func`2 errorCreator)
       at System.Net.Http.HttpRequestMessageExtensions.CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Exception exception)
       at aocform.Controllers.ValuesController.<>c__DisplayClass2.<Post>b__1(Task`1 t) in c:\Users\fred_malone\Documents\Visual Studio 2012\Projects\aocform\aocform\Controllers\ValuesController.cs:line 30
       at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException: 

App_Data フォルダーを確認すると、そこにファイルの一部が表示されます。この小さなパーツも、ある大きさで切れてしまうなど、いつも同じ大きさではありません。

maxRequestLengthと の両方maxAllowedContentLengthを大きな数に調整しましたが、成功しませんでした。

このメッセージは何を意味し、何を確認すれば修正できますか?

ありがとう。

4

0 に答える 0