0
votes

I have a .NET Server Control app that simply returns some HTML. I also need to embed several picture files into the assembly so that the HTML file can use them as its src= for each of them.

We will simply have a .HTML file that lives in the project as an embedded resource and the server control code will read this html and serve it up. Within THAT html, we will need to have all the picture src links (as well as CSS, js, etc) to point back to embedded resource files.

Does anyone know what code I would put in the HTML file for the pictures to make it point back to the embedded picture file?

I have to do this on a grand scale... hundreds of times. I really would like a programmatic approach to doing this so I can write a wrapper and never have to touch it again when we update the server control with new html, picture files, etc.

One might imagine a way to do this at compile time where I can loop through the embedded files with GetManifestResourceNames and then replace() the src links with the HTTP resource links I suppose?

Thank you for any guidance!

2
On a webcontrol i use this command: Page.ClientScript.GetWebResourceUrl(.....)bdn02
Thank you, bdn02, and you are exactly right. I can call that from the code behind in my server control. However, I was hoping to pull this off with straight HTML. In other words, I was hoping to make the server control "dumb" and only serve an HTML file back to the client. Inside of that HTML are, of course, references to js files, image files, etc. Instead of those src= calls being pointed to a URL, I want them to point to embedded resources from the .axd file. Is there anything in HTML to do that other than coding something in the PreRender of the server control to overwrite the HTML?RandyWhirl
This question is a little difficult to read, as some aspects are repeated somewhat, and there seems to be more than one actual question.Marcel

2 Answers

0
votes

Hm, your question covers quite many aspects. Let me repeat to see if I got it: You have an assembly, with a raw HTML file in it. This file references some items, which are to be found within this same assembly, and you want to have them served to the client upon request as well.

One possible solution might be this.

  • Instead of a raw HTML file, use a templated one. Then, feed all available resource names as proper URL's into the templating engine, to replace the placeholders.You may want to look at DotLiquid for this.
  • Create a HTTP handler for each file type you want to serve. Inside the handler, you pull the item from the resources of the dll and serve them.

Alternatively, if those resources are rather small, you want to have a look into the data URI scheme, to save the extra requests and omit the handler. With this you could replace the placeholders with the data URI's directly, and serve a single HTML file with everything in it in the frist place.

0
votes

Another choice is to have your .NET Server Control app check for optional GET arguments and return the image instead of the HTML.

Your original HTML request might be a simple:

GET netServerApp

Which returns the HTML with normal embedded links.

The HTML image links in the HTML might look like this:

<img src="netServerApp?src=Image1.svg">

or the like. Your server app would then return the appropriate image, instead of the HTML.

It means several round trips to get everything, but that is normal for HTML anyway.