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

2

6

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

I have a UploadController with a ActionResult looking somthing like this.

  [HttpPost]
  public ActionResult VideoUpload(int memberId)
  {
    var status= _docRepo.SaveDocument(DocumentType.Video, Request.Files, memberId);
        return Json(new { success = true, status = status});
  }

The files can be very large, i have increaset maxRequestLenght in web.config and can upload the files, but im worried about the security issue. So i tried this and its not working:

 <location path="VideoUpload">
        <system.web>
            <httpRuntime maxRequestLength="1024000" executionTimeout="600" />
        </system.web>
        <system.webServer>
            <security>
                <requestFiltering>
                    <requestLimits maxAllowedContentLength="1024000"/>
                </requestFiltering>
            </security>
        </system.webServer>
    </location>

Any ideas? (the upload method is using swfupload)

Lottielotto answered 8/11, 2011 at 10:52 Comment(1)
have you increased the page timeout as well or not?Desirae
A
1

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.

Anacreon answered 11/10, 2012 at 13:55 Comment(1)
Setting the MaxRequestLength property programmatically will apply site-wide.Sass
J
0

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});
   }
Juniper answered 11/10, 2012 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.