Search code examples
.netasp.nethttphandler

ashx vs aspx for file download


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?


Solution

  • 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.