MVC3操作文件大小限制 [英] MVC3 Action File Size Limit

查看:123
本文介绍了MVC3操作文件大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施基于jQuery的文件上传插件<一个href=\"http://blueimp.github.com/jQuery-File-Upload/\">http://blueimp.github.com/jQuery-File-Upload/.这里是一个示例应用程序MVC3,您可以下载<一个href=\"https://github.com/maxpavlov/jQuery-File-Upload.MVC3\">https://github.com/maxpavlov/jQuery-File-Upload.MVC3.

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:

@ *为了使用MVC行动作为Ajax调用处理程序,使用窗体声明下方。 (THE ONE注释掉)
  这是不建议,因为当使用MVC控制器来处理申请一个无法控制POST请求的maxMessageLength
  这就引起上传大型文件无用的功能,除非你SUCRIFICE安全,让大型
  POST消息大小站点范围。

@*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.

这是更好地使用HTTP处理程序处理上传请求,直到MVC框架提供方法来设置maxMessageLength ON
  PER ACTION基础* @

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

这仍然是这样?

我发现我可以设置&LT;的httpRuntime的maxRequestLength =X/&GT; 在web.config中,但我的理解是,这是一个安全漏洞。是这样也?

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?

我想preFER来处理我上传的控制器,而不是使用一个HttpHandler,但不想按文件大小的限制,不希望引入任何安全漏洞,如果我没有。

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.

更新:

根据这个帖子的文件上传Asp.net Mvc3.0 ,从而默认文件大小限制为4MB。我已经证实了这一限制<一个href=\"http://msdn.microsoft.com/en-us/library/e1f13641.aspx\">http://msdn.microsoft.com/en-us/library/e1f13641.aspx和理解的脆弱性。

According to this post File Upload Asp.net Mvc3.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.

这是上传直通超过4MB?控制器操作一个文件的唯一方法

推荐答案

您可以在设置上传大小限制的的web.config 的使用<具体的控制器操作A HREF =HTTP:// MSDN。 microsoft.com/en-us/library/b6x6shw7(v=vs.100).aspx\">location 元素:

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>

其中的首页的是控制器名称, UploadFiles 的是一个动作的名称。大小限制是40MB这里

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

不过,使用HTTP处理程序来处理文件上传,如果你问我是不是一个坏的解决方案。

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

这篇关于MVC3操作文件大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆