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)
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});
}
来源:https://stackoverflow.com/questions/8049263/can-i-increase-maxrequestlength-of-asp-net-request-for-mvc-controller-action-wit