Wednesday, June 5, 2013

SPSite.MakeFullUrl Lies To You and Me!!

Today we are complaining about this method of SPSite: MakeFullUrl

The complaint is this: In SharePoint 2010, it always returns the root web url, no matter what site collection instance it is used upon.

Here is the example: Given the following code block, what would you expect the resulting output to be when used in different site collection contexts:

Code
Response.Write(SPContext.Current.Site.MakeFullUrl("/Lists/Tasks"));
 
Test 1
Hitting the code at http://sharepoint/_layouts/test.aspx – the ROOT site collection - results in the output:
http://sharepoint/Lists/Tasks

Test 2
Hitting the code at http://sharepoint/sites/AnotherSiteCollection/_layouts/test.aspx – the AnotherSiteCollection site collection - results in the output:
http://sharepoint/Lists/Tasks

Conclusion
Since MakeFullUrl is an instance method of an SPSite object, you would think the result URL would take the SPSite into consideration. It does not, and therefore it sucks.
 
© I caught you a delicious bass.
Back to top