locked
Pull resources from assembly in HttpHandler RRS feed

  • Question

  • User1251099129 posted

    I have developed a WebControl that essentially displays a header text by loading a Flash movie in HTML, passing some parameters (like the header text) from the WebControl to the movie.

    Due to issues with Adobe Flash Player and Internet Explorer when rendering Flash content inside <form> tags, and rendering multiple movies on the same page, I have been forced to display the Flash content inside an <iframe>. The WebControl writes out the <iframe> tag, with a src attribute set to the HttpHandler address, which in turn writes out the necessary HTML to render the Flash movie.

    This works great, but I want to pull the control resources (Flash movie + some JavaScript files) from the assembly in the HttpHandler. Before I went down the <iframe> route, I referenced the JavaScript and Flash movies neatly by GetWebResourceUrl from the Page object. But with the new solution, the JavaScript has to be placed separately in the website. I want everything to be contained in the same assembly for easy deployment and updates.

    So, given this, is it possible to do something like GetWebResourceUrl from the HttpHandler class? 

    Tuesday, July 3, 2007 11:46 AM

Answers

  • User-802213120 posted

    You need to add the .swf file to your project and set its "Build Action" to "Embedded Resource".  This step is very important and you need to make sure to do it or it will not work.

    Next you need to reference the embedded resource with an assembly level attribute, named WebResource.  From there it simply requires a call to the GetWebResourceUrl method.  The only tricky part in any of this is that the path for the underlying .swf file my be qualified with the assembly name and any directories that it is contained in.

    Example:

      

    1    using System;
    2    using System.Web.UI;
    3    
    4    [assembly: WebResource("MyAssembly.MyFolder.MySubFolder.MyFile.swf", "application/x-shockwave-flash")]
    5    namespace Testing
    6    {
    7        public class TestPage : Page
    8        {
    9            protected override void OnInit(EventArgs e)
    10           {
    11               string url = Page.ClientScript.GetWebResourceUrl(GetType(), "MyAssembly.MyFolder.MySubFolder.MyFile.swf");
    12           }
    13       }
    14   }
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2007 10:27 AM

All replies

  • User1251099129 posted

    No one?

    Is it perhaps possible to use Reflection together with a HttpHandler, and somewhat replicate what GetWebResourceUrl does?

    Friday, July 6, 2007 1:07 PM
  • User-802213120 posted

    You need to add the .swf file to your project and set its "Build Action" to "Embedded Resource".  This step is very important and you need to make sure to do it or it will not work.

    Next you need to reference the embedded resource with an assembly level attribute, named WebResource.  From there it simply requires a call to the GetWebResourceUrl method.  The only tricky part in any of this is that the path for the underlying .swf file my be qualified with the assembly name and any directories that it is contained in.

    Example:

      

    1    using System;
    2    using System.Web.UI;
    3    
    4    [assembly: WebResource("MyAssembly.MyFolder.MySubFolder.MyFile.swf", "application/x-shockwave-flash")]
    5    namespace Testing
    6    {
    7        public class TestPage : Page
    8        {
    9            protected override void OnInit(EventArgs e)
    10           {
    11               string url = Page.ClientScript.GetWebResourceUrl(GetType(), "MyAssembly.MyFolder.MySubFolder.MyFile.swf");
    12           }
    13       }
    14   }
    
     
    Saturday, July 7, 2007 10:27 AM
  • User-802213120 posted

    You need to add the .swf file to your project and set its "Build Action" to "Embedded Resource".  This step is very important and you need to make sure to do it or it will not work.

    Next you need to reference the embedded resource with an assembly level attribute, named WebResource.  From there it simply requires a call to the GetWebResourceUrl method.  The only tricky part in any of this is that the path for the underlying .swf file my be qualified with the assembly name and any directories that it is contained in.

    Example:

      

    1    using System;
    2    using System.Web.UI;
    3    
    4    [assembly: WebResource("MyAssembly.MyFolder.MySubFolder.MyFile.swf", "application/x-shockwave-flash")]
    5    namespace Testing
    6    {
    7        public class TestPage : Page
    8        {
    9            protected override void OnInit(EventArgs e)
    10           {
    11               string url = Page.ClientScript.GetWebResourceUrl(GetType(), "MyAssembly.MyFolder.MySubFolder.MyFile.swf");
    12           }
    13       }
    14   }
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2007 10:27 AM
  • User-913168504 posted

    The real question here is how to access resource from class implementing IHttpHandler. My understanding is that Page object is no accessible there in this context (Page.ClientScript...). The best solution would be getting the refference only (URL to WebResource.axsd). Example would be serving content of the IFrame from web server control, where images (part of the served content) are embeded in the dll web server control sits in.

    Alex

    Thursday, February 12, 2009 5:50 PM