Can I increase maxRequestLength of ASP.NET request for MVC Controller Action with additional parameters?

帅比萌擦擦* 提交于 2019-12-05 06:02:59
Heretic Monkey

MVC Controller Actions do not use the location section of the Web.config. See this answer for more information. You can increase it programmatically via the MaxRequestLength property.

Have you thought about calling the action controller method asynchronously, even with the possibility of calling a new thread to save the document so that the web page isn't waiting on the response and risking a timeout.

Use a jquery ajax call to call your controller and Task Parallel Library to save the document. The ajax call can do something with the success/failure handler is called after getting the response.

Looks something like this

   $(function() {
        $('selector').click(function() {
            var id = $('selector for id').val()
            $.ajax({
                type: "POST",
                url: "/Controller/VideoUpload",
                data: { memberId: id },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    $("selector for status").(msg);
                },

            });
        });
    });

Action Method would look something like this, though this may not be exact. You wouldn't necessarily have to do this either as the ajax post should allow the method call to execute without the browser waiting for the response.

   [HttpPost]
   public ActionResult VideoUpload(int memberId)
   {
       var status = Task.Factory.StartNew(() => _docRepo.SaveDocument(DocumentType.Video, Request.Files, memberId));
           return Json(new { success = true, status = status.Result});
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!