locked
Using Embedded Resources Without a UserControl RRS feed

  • Question

  • User-994427227 posted

    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);

    Thanks

    Mark


    Saturday, November 14, 2009 2:31 PM

Answers

  • User1566012831 posted

    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.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2009 5:56 AM

All replies

  • User1566012831 posted

    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()?



    Sunday, November 15, 2009 12:23 AM
  • User-994427227 posted

    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.


    Mark

    Tuesday, November 17, 2009 12:33 AM
  • User1566012831 posted

    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.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2009 5:56 AM