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.
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 %>" />
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.
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.
来源:https://stackoverflow.com/questions/337781/creating-custom-url-tokens-in-asp-net-a-la-moss