0

I have embedded a javascript library, some CSS and some images into a class library as embedded resources.

I have created custom controls to access both the javascript and the CSS, but within the CSS, there are certain parts that use background images that are referenced via url(../../img/img.png). How would i handle these requests?

P.S. i have already thought about writing a IHttpHandler to capture and redirect these requests, but i would rather not have to edit web.config further to achieve this.

bizzehdee
  • 20,289
  • 11
  • 46
  • 76
  • Just to make sure that I'm getting it right: you are looking for a solution to use the background images which are embedded in the library. Wouldn't that affect performance, as the resources will not be cached? In fact, I'm quite curious how you use the CSS in your controls, could you also provide a code sample? Actually, what is the purpose of embedding the resources, to start with? – Alex Filipovici Jul 17 '13 at 11:27
  • i am creating a library of user controls and for ease of packaging, i would like to simply package a single dll file rather than hundreds of images and js and css files and a single dll file. – bizzehdee Jul 17 '13 at 11:51
  • How do you use the embedded CSS/JS files with your controls? – Alex Filipovici Jul 17 '13 at 11:58
  • each of the CSS/JS is a control in its self – bizzehdee Jul 17 '13 at 12:12
  • How about creating an `IHttpModule` implementation which would get the embedded resources from the library and save them to the server if they don't exist on the server path? – Alex Filipovici Jul 17 '13 at 12:47
  • isnt that the same as a `IHttpHandler` ? – bizzehdee Jul 17 '13 at 12:50
  • What's your issue with editing `web.config`? – dav_i Jul 18 '13 at 20:41
  • Please clarify, is this Webforms, MVC or something else? It's an easy answer, but it depends on your platform – nathanchere Jul 23 '13 at 08:10
  • this is a library of widgets, not a web app its self so webforms/mvc doesnt come in to it as it could be either. – bizzehdee Jul 23 '13 at 08:36
  • You can consider me as rookie. But just on side note can you not use nuget in order to distribute your usercontrol? That way as part of nuget package installation you have full control over file/folder structure and you can add resources that way as well. So you will not have to worry about any of issues come along with new solution. Just a thought as I said. I am not sure whether this is comment or probable answer :). – TorontoKid Jul 23 '13 at 18:23
  • There is the web resource handler that is built in. You use it with the Page.ClientScript.GetWebResourceUrl method. Replace your paths in the css with substitution tags <%= Webresource(" ... ") %> – user1985513 Jul 23 '13 at 19:31
  • see [here](http://stackoverflow.com/a/40399162/5137413) for solution I hope this sulotion help you – Ali Sadri Nov 03 '16 at 10:34

3 Answers3

1

Unless I'm mistaken, it sounds like you are looking for the substitution feature of embedded javascript/css. Go to this KB article, and search for "PerformSubstitution": Article

Michael
  • 498
  • 3
  • 13
1

Duplicate: How to reference embedded images from CSS?

<% = WebResource("image1.jpg") %>

You can use above statement inside your CSS file, and while you register your CSS with WebResourceAttribute, you can set "PerformSubstitution" to true

Default.css
body{
    background: <%=WebResource("xyz.jpg")%>
}



[assembly, WebResource("Default.css","text/css", PerformSubstitution=true)]
[assembly, WebResource("xyz.jpg","image/jpg")]
Community
  • 1
  • 1
Akash Kava
  • 39,066
  • 20
  • 121
  • 167
0

If it's not too big an image and target browsers are acceptable, you could use a Data URI...

http://websemantics.co.uk/online_tools/image_to_data_uri_convertor/