Monday, May 08, 2006

URL Rebasing in MasterPages

Did you know about URL Rebasing in MasterPages? - I didn't.

Often, MasterPage and Slave (or ContentPage) are not located in the same directory-level. So you will run into trouble if you have for example images on the MasterPage referenced like this:

<IMG src="images/spice.jpg" />

The ContentPage in a SubDirectory can not resolve the URL and you will get an 404-Error.

What is the Solutions?

Just put an runat="server" and and id="yourID" attribut to the image and the runtime will try to “rebase” relative URLs it finds on server-side controls inside a MasterPage .

This means the following relative path will work, no matter where the MasterPages and ContentPage :

<IMG id="spiceImg" src="images/spice.jpg" runat="server"/>

Cool!

1 comment:

Anonymous said...

Good job; works nicely.