Creating custom URL tokens in ASP.NET (a la MOSS)

北城余情 提交于 2019-12-09 23:32:01

问题


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.


回答1:


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 %>" />



回答2:


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.




回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!