Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

asp.net mvc 3 - MVC3 Action File Size Limit

I'm implementing a jquery based file upload plugin http://blueimp.github.com/jQuery-File-Upload/. There is a sample MVC3 app that you can download https://github.com/maxpavlov/jQuery-File-Upload.MVC3.

The author of the sample has a comment in the Home View:

@*IN ORDER TO USE MVC ACTIONS AS HANDLERS OF AJAX CALLS, USE THE FORM DECLARATION BELOW. (THE ONE COMMENTED OUT) IT IS NOT ADVISED SINCE WHEN USING MVC CONTROLLER TO HANDLE REQUESTS ONE CAN'T CONTROL THE maxMessageLength OF THE POST REQUEST THIS CASTS THE FUNCTIONALITY OF UPLOADING LARGE FILES USELESS, UNLESS YOU SUCRIFICE THE SECURITY AND ALLOW LARGE POST MESSAGE SIZES SITE-WIDE.

IT IS BETTER TO USE HTTP HANDLER TO PROCESS UPLOAD REQUESTS UNTIL MVC FRAMEWORK PROVIDES WAYS TO SET maxMessageLength ON PER ACTION BASIS *@

Is this still the case?

I've found out I can set the <httpRuntime maxRequestLength="x" /> in the web.config, but my understanding is that this is a security vulnerability. Is the case also?

I would prefer to handle my upload in the controller instead of using an HttpHandler but don't want to be limited by file size and don't want to introduce any security vulnerabilities if I don't have to.

Update:

According to this post File Upload ASP.NET MVC 3.0 the default file size limit is 4mb. I've confirmed this limit http://msdn.microsoft.com/en-us/library/e1f13641.aspx and understand the vulnerability.

Is this the only way to upload a file thru a controller action beyond 4mb?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could set upload size limit in web.config for concrete controller action using location element:

<configuration>
    <location path="Home/UploadFiles">
        <system.web>
            <httpRuntime maxRequestLength="40960"/>
        </system.web>
    </location>
</configuration>

Where Home is a controller name and UploadFiles is an action name. Size limit is 40MB here.

Still, using Http Handler to process file uploads is not a bad solution if you ask me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...