Last post Jul 23, 2009 05:12 PM by kahlua
Jul 22, 2009 08:54 PM|kahlua|LINK
I have an http module that I use to inspect all incoming URLS. In some cases, I would like to dish out a file such as a png. I followed the process all the way through to the Response.WriteFile method however in the web browser I get the asp.net resource
cannot be found error. Is it possible to use Response.WriteFile with an http module?
context.Response.ContentType = "image/png";
I have verified that AssetPath variable exists. This works in an http handler however I need to use this in an http module. Thanks!
Jul 22, 2009 09:28 PM|RickNZ|LINK
From which event handler are you trying to send the file? Has the ASP.NET handler already run?
Have you looked at the page output with Fiddler?
Jul 22, 2009 10:41 PM|kahlua|LINK
I'm doing this in the BeginRequest event. Not sure what you mean by has the handler already run, I can see my breakpoints hit the Response.WriteFile line. There are no other modules or httphandlers that should be hooked up in the web.config. As for fiddler,
not sure how it would help in this case since the page that is emitting from IIS is the resource not found error page.
Some more info, if i go to http://localhost/test.png, the Response.WriteFile is spitting out the file from another location. This works as a http handler, but once converted to an httpmodule, it says it cant find it and lists the resource url as: /test.png
Jul 22, 2009 11:56 PM|RickNZ|LINK
The way that HttpModules work is that they give you access to the events surrounding an eventual call to an HttpHandler. The ASP.NET HttpHandler is the Page class, for example. The specific Handler to be called is determined by the file's extension. Even
static files have their own HttpHandler.
So if you write some info to the output stream in BeginRequest for test.png, then when the static Handler runs after that, if that file doesn't exist, it will cause an error.
To prevent the HttpHandler from being called, you should call HttpApplication.CompleteRequest():
HttpApplication application = (HttpApplication)source;
Jul 23, 2009 05:12 PM|kahlua|LINK
That worked, thanks!