bizzehdee
bizzehdee

Reputation: 21013

Handle file requests from CSS files embedded within an assembly

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.

Upvotes: 0

Views: 1046

Answers (3)

Akash Kava
Akash Kava

Reputation: 39916

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")]

Upvotes: 1

Chris Sterling
Chris Sterling

Reputation: 99

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/

Upvotes: 0

Michael
Michael

Reputation: 498

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

Upvotes: 1

Related Questions