Last post Nov 17, 2009 05:56 AM by RickNZ
Nov 14, 2009 02:31 PM|sisdog|LINK
I have a dll project that has HttpHandler code that is referenced in my ASP.Net web project. Now, when a URL comes into my web app that is sent to my HttpHandler, I'm trying to return HTML that has references to resources (images, js, css, etc.) that are
embeeded in my dll project. But everywhere I've looked people are describing how to do this WITHIN A USERCONTROL. But I don't have a user control. I just have my IHttpHandler that receives the HttpContext and I build my http response through HttpContext.Response.
This is a code sample from MSDN. It seems like the only way to use the GetWebResourceUrl() method is to have a reference to a ClientScriptManager, which in turn expects to have access to the Page reference. Can I get to this from my HttpContext, which
is the only thing I have access to in my HttpHandler?
// Define the resource name and type.
String rsname = "script_include.js";
Type rstype = typeof(ClientScriptResourceLabel);
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Write out the web resource url.
ResourcePath.InnerHtml = cs.GetWebResourceUrl(rstype, rsname);
Nov 15, 2009 12:23 AM|RickNZ|LINK
The Page class is really just one implementation of an HttpHandler.
If you need controls, etc, is there a reason why you still prefer to use a custom HttpHandler? Why not just use a Page, and emit whatever special codes you need to, using Response.Write()?
Nov 17, 2009 12:33 AM|sisdog|LINK
Thanks for the response Rick. The crux of this is that I don't want controls, that's my issue. I don't have access to a Page context variable.
I resolved this by doing my own HttpHandler for a specific URL (a relative folder path) that serves up all my dll resources. Then I read in a binary stream from the assembly of my dll and stream to the Response output. I'm just worried about having all
my code do this and not taking advantage of any cool caching or streaming that asp.net might do a better job of than me. But hopefully most browsers will intelligently cache these resources so my app code wouldn't get over-burdened serving this stuff up.
Nov 17, 2009 05:56 AM|RickNZ|LINK
While some types of output caching are implemented by the Page Handler, you still have access to the ASP.NET Cache object from a custom Handler, via context.Cache.
You can also enable client-side caching from your Handler, in case that might help.