views:

768

answers:

3

In ASP.NET, the tilde (~) is treated as a token in URLs and treats paths prefixed with that as relative to the application root. This is well-known functionality.

In MOSS, there are other tokens, such as ~sitecollection/mypath... which behaves in a similar way, but treats the path as relative to the site collection root. How is this accomplished? After a cursory search I could not find any info on how to add tokens like this to the .NET URL resolution mechanism.

A: 

I don't know for sure - but I'd bet that code is buried in one of the SharePoint HTTPModules or HTTPHandlers that run for every request.

Greg Hurlman
A: 

I don't think it would be there since it is not a universal token replaced anywhere in the output of the handler. It happens at the URL resolution level in a server control, which makes me think it might have been somewhere in the classes related to control building or parsing, but I did not find anything there.

Rex M
+3  A: 

It may not be the only place, but SPUtility.GetServerRelativeUrlFromPrefixedUrl() will parse URLs with ~site and ~sitecollection. MOSS also provides SPUrlExpressionBuilder for declarative use:

<link runat="server" rel="stylesheet" type="text/css"
      href="<% $SPUrl:~SiteCollection/Style Library/MyStyles/style.css %>" />
dahlbyk
FWIW, both of those links are the same. This is the correct link for SPUtility.GetServerRelativeUrlFromPrefixedUrl(): http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.getserverrelativeurlfromprefixedurl.aspx
Abs