Making master page images relative to the current site collection

When you are working with master pages in SharePoint, there are times that you will put in your own custom images. This is fine, except it can often be tricky to get the src attribute right if your master page is going to be used in a site collection that is not at the root of the web site (for example /sites/mynewsite).
To get the image URL right, use this code:

1:<imgsrc=""””alt=””My Image””runat=””server””/>
The important thing to note here is the runat=””server”” attribute, without it the tag will just spit out the code as it is without inserting the correct URL. So by doing this your master page will become mobile enough to be run from any site collection, no matter where it resides.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s