ASP.NET 2.0–Web Resources and SharePoint

One of the many new features in ASP.NET 2.0 is called Web Resources. Basically this allows you to store resources like images, scripts and so on, in an assembly. You can do this by using the WebResource attribute. This attribute can be applied on assembly level like this

[assembly: WebResource("image1.jpg", "image/jpeg")]
[assembly: WebResource("help.htm", "text/html", PerformSubstitution=true)]

If you want to use any of your resources in an ASP.NET form (or user control):

<img alt="help image" src=&lt;% = WebResource("image1.jpg") %&gt; />

When the page is rendered the image will point to something like:

<img alt="help image" src=WebResource.axd?d=bZaDBpnwEO_aWezomeGuYatieDaddy/>

Many of the default ASP.NET 2.0 controls use this feature to store scripts and images, a good example is the TreeView control. If you want to use the same technique in SharePoint, for example when you want to run ASP.NET 2.0 user controls you will face an issue. The problem is that the ISAPI filter of SharePoint will try to process the request to WebResource.axd,so you won’t be able to retrieve any resources.

Leave a Reply