ashx 与 aspx 文件下载

发布于 2024-10-07 19:22:56 字数 312 浏览 10 评论 0原文

在一个基本场景中,我有一个带有要下载的文件和下载它们的链接按钮的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把昨日还给我 2024-10-14 19:22:56

您是否计划从应用程序中的多个位置重用下载功能?如果您想将下载与应用程序的其余部分松散耦合,通用处理程序是一个很好的方法,因为您本质上是在创建服务。否则,如果您只计划从该按钮下载,并且仅从该按钮下载,则可以将逻辑留在那里。请记住,有些事情会让您的应用程序变得过于复杂。

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.

口干舌燥 2024-10-14 19:22:56

我为此使用了 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.

雨巷深深 2024-10-14 19:22:56

这真的取决于你。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文