ashx 与 aspx 文件下载
在一个基本场景中,我有一个带有要下载的文件和下载它们的链接按钮的 GridView,创建自定义 http 处理程序来流式传输这些文件与简单地从下载链接按钮的事件处理程序进行流式传输相比有什么好处吗? ?
编辑:
正如一些建议的代码重用将有利于处理程序,但在这种特殊情况下这不是问题。处理程序也更快,因为它避免了页面生命周期,但是这种轻微的性能改进可能不值得在我的特定情况下创建处理程序。
现在唯一想到的是(假设使用相同的 aspx 页面方法)在 GridView 位于 UpdatePanel 内部的情况下是否有任何特殊考虑?
In a basic scenario where I have a GridView with files to download and link buttons to download them, is there any benefit at all for creating a custom http handler for streaming those files as opposed to simply streaming from the event handler of the download link button?
Edit:
As some suggested code reuse would favor the handler, however it's not an issue in this particular case. The handler is also faster being that it avoids the page life cycle, however this slight performance improvement is probably not worth creating a handler for in my particular situation.
The only thing that comes to mind now is (assuming using the same aspx page approach) whether there is any special consideration in a situation where the GridView is inside an UpdatePanel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否计划从应用程序中的多个位置重用下载功能?如果您想将下载与应用程序的其余部分松散耦合,通用处理程序是一个很好的方法,因为您本质上是在创建服务。否则,如果您只计划从该按钮下载,并且仅从该按钮下载,则可以将逻辑留在那里。请记住,有些事情会让您的应用程序变得过于复杂。
Are you planning on reusing the functionality of your download from more than one spot within your application? If you want to loosely couple your download from the rest of your application, a
Generic Handler
is a good way to go, as you are essentially creating a service. Otherwise, if you are only planning on having that download from that button, and only that button, you can leave the logic there. Remember, there is such thing as making your application more over complex than it need be.我为此使用了 ASHX,因为我认为它们占用的空间更小,而且我根本不需要 UI 来流式传输文件,所以这些对我来说是完美的。
I'm using ASHX for this, since I think they have a smaller footprint and since I need no UI at all for streaming a file, these are perfect for me.
这真的取决于你。 ASHX 不具有与 ASPX 相同的页面生命周期(无 OnLoad 等),由于开销较低,通常被认为速度更快,并且没有与 Web 表单关联的无关标记文件。
如果您的应用程序合适,您还可以考虑使用 Web 服务 (ASMX)。
It's really up to you. ASHXs don't have the same page lifecycle as an ASPX (no OnLoad, etc), are generally considered to be faster due to low overhead, and don't have the extraneous markup file associated with a webform.
You might also consider a web service (ASMX) if appropriate in your application.