GarethOwen
GarethOwen

Reputation: 6133

Best way for ASP.NET App to deliver images: use httphandler or static resource

On our web server we want to provide urls that can be used in HTML elements, for displaying user profile pictures.

I could do this in two ways:

are there any benefits of one method over the other?

Upvotes: 3

Views: 382

Answers (3)

nunespascal
nunespascal

Reputation: 17724

Let IIS deal with them. Serving images from a handler can take up a lot of resources. Don't do that unless absolutely necessary.

If your site has a lot of images, this means that many extra requests for Asp.net to handle. Asp.net needs quite a lot more resources per request than what IIS would need to push out a static file.

Upvotes: 2

Gavin
Gavin

Reputation: 6394

Whilst allowing IIS to handle the images would be easier, it depends on whether or not you want to compress the files as they are sent?

Certain versions of IIS support GZIP compression, thus meaning you can compress the files as IIS serves them, however, older versions of IIS may not, meaning if you need to compress the files, you would have to use an HTTPHandler or similar to compress and serve them.

Upvotes: 2

Oded
Oded

Reputation: 499212

Not handling images via ASP.NET but letting IIS deal with them as static content and circumventing the ASP.NET pipeline altogether would be fastest.

Implementing an HttpHandler, apart from requiring code, would require the ASP.NET pipeline to be involved - this takes more resources from the server.

Basically, if the content is static, let it be static and let IIS handle it.

Upvotes: 4

Related Questions