Using WebResource to embed an external library image RRS feed

  • Question

  • User1407514265 posted

    Hello guys,

    I have one dll where I want to store all the common resources for a web applications. With this I want to prevent that another developers have to include the same resources again and again on their own dll. The common resources are images, css, js and ascx files; this library is named Common.Web.Resources.dll and has the default Namespace Common.Web.Resources. Inside this dll I have registered an image on the AssemblyInfo.cs file using:

    // Registering the image images/icons/add.png
    [assembly: WebResource("Common.Web.Resources.images.icons.add.png", "image/png")]

    I have one Web Application project named CommonWebResourcesTest, inside it I have registered a css resource using:

    // registering the file images/icons/WebResourceTest.css
    [assembly: WebResource("CommonWebResourcesTest.images.icons.WebResourceTest.css", "text/css", PerformSubstitution=true)]

    This project is referencing to the last dll. Inside this project I want to use the add.png as the background of a div. Inside the WebresourceTest.css file I have the next class:

    .testIcon {
    background-image: url( <%= WebResource("Common.Web.Resources.images.icons.add.png") %> );

    This code is transformed on the next one:

    .testIcon {
    background-image: url(WebResource.axd?d=RCLV6OkRydi5c--se1_feHGK-SiFBFPDZbaTidLSEddef1gjTfSYWE4M2zXXLHbaUzLSIn7QB639wttU4t8wbA2&t=633840504966957850);

    Unfortunately the file


    doesn't exist. Do you know another way to do this kind of things?.

    Thanks in advance.

    Friday, July 24, 2009 7:05 PM


All replies

  • User1571885900 posted


    Are you seeting 'Build Action' to 'Embedded Resource' ?

    Refer this blog http://blogs.runatserver.com/bpelletier/archive/2009/06/20/display-images-from-embedded-resources-in-asp-net.aspx

    Saturday, July 25, 2009 1:12 AM
  • User1407514265 posted

    Yes, I setted the Build Action to Embedded Resource. I forgot to mention that I tested the external resource using an Image Control and setting the next property:

    // Creating the Image on an aspx page on my CommonWebResourcesTest project to
    // test the image resource inside Common.Web.Resources.dll
    // The ResourceManager.Instance is a singleton CompositeControl inside 
    // Common.Web.Resources.dll
    AddIcon.ImageUrl =  Page.ClientScript.GetWebResourceUrl(typeof(ResourceManager.Instance),

    On the .aspx page the Image is shown well. I'm using the next code to include the css resource on my CommonWebResourcesTest project

    // Code to include the css resource inside the CommonWebResourcesTest project
    // on the aspx page
    // The ResourceManagerProxy is a CompositeControl inside the CommonWebResourcesTest
    // project used just to get access to the project resources
    string includeTemplate = @"<link rel=""stylesheet"" type=""text/css"" href=""{0}"" />";
    string cssLocation = Page.ClientScript.GetWebResourceUrl(typeof(ResourceManagerProxy),
    LiteralControl cssControl = new LiteralControl(string.Format(includeTemplate, cssLocation));

    I don't know if the problem is because the css and the image are on different resources.

    Thanks for your reply.

    Saturday, July 25, 2009 3:25 PM
  • User-2106054853 posted


    Could you share a demo that can reproduce this issue? You can upload the project to http://skydrive.live.com/ and paste the download link here for me to test.

    Monday, July 27, 2009 2:17 AM
  • User1407514265 posted

    Thanks for your reply. Here is the download Link


    It's a solution containing the Resources project and the Test project.

    Thanks for your help.

    Monday, July 27, 2009 3:24 PM
  • User-16411453 posted

    you have to call it up using the client script manager, should not be hard to translate that to vb. With vb, you have to store the image in the root folder of the project, and mark it as embedded resource

    Dim cs As ClientScriptManager = Me.Page.ClientScript
            Dim rsType As Type = Me.GetType()

    imageurl = cs.GetWebResourceUrl(rsType, "AsemblyName.100pxShim.gif").ToString()

    Monday, July 27, 2009 7:59 PM
  • User1407514265 posted

    Thanks for your reply,

    As I mention on my previous posts, the problem is not using the GetWebResourceUrl on the code behind. It's using the WebResource function inside the .css file because It's generating the URL for the image, unfortunately that URL is not as same as using the GetWebResourceUrl function and the image is not being found.

    Monday, July 27, 2009 11:03 PM
  • User-16411453 posted

    I don't think it was intended to be used that way.

    Tuesday, July 28, 2009 12:51 PM
  • User-2106054853 posted

    Thanks for your reply. Here is the download Link


    It's a solution containing the Resources project and the Test project.

    Thanks for your help.


    I cannot access it. Could you double check the URL?

    Tuesday, July 28, 2009 10:04 PM
  • User1407514265 posted

    Sorry about it,

    I'm copying the link to the zip file from skydrive. I hope it works.


    Wednesday, July 29, 2009 10:42 AM
  • User-2106054853 posted


    The problem is caused by the assembly of the type is not the assembly that contains the resource. Please refer to revised code:


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 30, 2009 2:17 AM
  • User1407514265 posted

    Thanks for your reply,

    I tested the code that you provided me but unfortunately It's not the solution that I was looking for; and this is because the css file must be inside the CommonWebresourcesTest project and not inside the Common.Web.Resources.dll assembly. But anyway, It seems that the KISS solution is to have one axd handler inside the Common.Web.Resources.dll assembly, register it on the web.config and then call it from the .css file in order to get the image.

    For all your answers, thank you very much.

    Thursday, July 30, 2009 10:34 AM
  • User94547940 posted

    Could you please describe in more detail the solution you implemented? I have exactly the same problem.

    Thanks in advance

    Monday, August 3, 2009 7:39 PM
  • User1407514265 posted

    Here you can find one example about custom axd handlers.


    Thursday, August 6, 2009 1:39 AM