Asp.Net 中信任大文件上传
我需要在我的托管 (godaddy) 中等信任 asp.net 应用程序中支持大文件上传。
它显然需要响应进度指示,因此自己处理流很重要。
这一切看起来都很简单,并且在完全信任的情况下运行良好:
1.编写一个监听文件上传的HttpModule。
2.使用反射从Context中获取HttpWorkerRequest对象。
3.将流写入 FileStream
一切都很好,除了在尝试从中等信任的上下文中获取 HttpWorkerRequest 对象时不断收到权限异常之外。无论我使用反射还是使用 System.IServiceProvider.GetService() 来获取对象(显然使用反射),我都会收到相同的错误。
我也尝试过使用 System.Web.HttpPostedFile。它有一个属性InputStream。但这个对象似乎在初始化时上传整个文件,所以不好。
我用谷歌搜索自己很累,找不到其他选择。
即使让用户拥有 HttpWorkerRequest 对象存在安全风险,框架肯定会提供另一种方法来处理文件流,当 Method="POST" 和 enctype="multipart/form-data"
任何想法都会很棒
谢谢
I need large file upload support in my hosted (godaddy) medium trust asp.net app.
It obviously needs to be responsive with indication of progress, so handling the stream myself is important.
This all seems pretty simple and works well when in full trust:
1.Write an HttpModule that listens for file uploads.
2.Get the HttpWorkerRequest object from the Context using reflection.
3.Write out stream to a FileStream
All very well and good except that I keep getting permission exceptions when trying to get the HttpWorkerRequest object from the context in medium trust. Whether I use reflection or I use System.IServiceProvider.GetService() to get the object (which is clearly using reflection), I get the same error.
I have also tried using System.Web.HttpPostedFile. It has a property InputStream. But it seems this object is uploading the entire file on initialization, so no good.
I have googled myself tired, and can't find another alternative.
Even if it is a security risk to let users have the HttpWorkerRequest object, surely the framework provides another way to handle the stream of files when Method="POST" and enctype="multipart/form-data"
Any ideas would be great
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以尝试从
context.Request.InputStream
读取。You could also try reading from
context.Request.InputStream
.