Ever since I got my hands on .NET 2.0 I noticed the handler webresource.axd which seemed to provide a similar function as what I was using handlers for.
I mark them before compiling as embedded resource and then later on read them out via reflection and they get served up by the browser.
I probably don’t have to explain that (as long as your parameters don’t change) this scripts get cached by the browser so they will only be downloaded once and re-used afterwards.
Well in asp.NET 2.0 there is a feature that uses webresource.axd to handle all kinds of embedded resources (images, pages, etc…)
Using Web Resources
Imagine I am writing an HtmlEditor control and I want to use a stock bold button icon. Here’s what I’d do:
Embed “Bold.gif” as a resource with the same name into my control’s assembly.
Mark it as Web-accessible via the attribute:
[assembly: WebResource("Bold.gif", ContentType.ImageGif)]
Use the GetWebResourceUrl() method on Page to get a URL that can be rendered out to the client.
boldButton.ImageUrl = Page.GetWebResourceUrl(typeof(HtmlEditor), "Bold.gif");
This results in a URL of the form: