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

Is it possible to increase the maxRequestLength of an ASP.NET request for an MVC Controller action with additional parameters?

I have a UploadController with an ActionResult that looks something like this.

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

Files can be very large, I have increaset maxRequestLenght in web.config and you can upload files, but I'm worried about a security problem. So I tried this and did not work:

  <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 boot method uses swfupload)

+6
source share
2 answers

MVC controller actions do not use the location section in Web.config. See this answer for more information . You can programmatically increase it using the MaxRequestLength property .

+2
source

You thought about calling the action controller method asynchronously, even with the ability to call a new thread to save the document so that the web page does not expect a response and does not risk a timeout.

Use jquery ajax call to call your controller and parallel task library to save the document. An ajax call might do something with a success / failure handler called after receiving a response.

It 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); }, }); }); }); 

The method of action will look something like this, although it may be inaccurate. You do not have to do this, as the ajax message should allow the method call to execute without a browser waiting for a 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}); } 
0
source

Source: https://habr.com/ru/post/901011/


All Articles