I have an httpModule that modifies the output stream of aspx page-requests. However, now with IIS7.5 Integrated mode, it's also modifying the output stream of images. Is there a way to tell, without the brute-force "check-file-extension" method, to determine
if the output is an image?
I've tried:
If HttpContext.Current.Response.ContentType = "text/html" Then
'Not an image?
End If
But ContentType IS "text/html" on an image request inside the httpModule.
The problem with checking for Response.ContentType is that the content type is probably not set yet by the handler responsible for serving the file (most likely the StaticFileHandler). So unless you're using a post handler Application/Module event the ContentType
will still be at the default which is text/html.
Extension checking is pretty efficient though (use Path.GetExtension() ) to make this easy.
Thanks. I was hoping there was some kind of Request.Type that would tell me if the request was static (image file, css, js, etc) or active (aspx, asmx, axd, etc)...
ojm37
Contributor
2248 Points
832 Posts
Detecting an image in an httpModule
Oct 27, 2011 05:33 PM|LINK
I have an httpModule that modifies the output stream of aspx page-requests. However, now with IIS7.5 Integrated mode, it's also modifying the output stream of images. Is there a way to tell, without the brute-force "check-file-extension" method, to determine if the output is an image?
I've tried:
But ContentType IS "text/html" on an image request inside the httpModule.
Ideas?
rstrahl
Contributor
2233 Points
375 Posts
ASPInsiders
MVP
Re: Detecting an image in an httpModule
Nov 15, 2011 02:52 AM|LINK
Nope you need the brute force approach.
The problem with checking for Response.ContentType is that the content type is probably not set yet by the handler responsible for serving the file (most likely the StaticFileHandler). So unless you're using a post handler Application/Module event the ContentType will still be at the default which is text/html.
Extension checking is pretty efficient though (use Path.GetExtension() ) to make this easy.
+++ Rick ---
West Wind Technologies
Making waves on the Web
www.west-wind.com/weblog
ojm37
Contributor
2248 Points
832 Posts
Re: Detecting an image in an httpModule
Nov 15, 2011 01:20 PM|LINK
Thanks. I was hoping there was some kind of Request.Type that would tell me if the request was static (image file, css, js, etc) or active (aspx, asmx, axd, etc)...