This conversation pop ups every couple of months - in varying forms - but the question that is never really fully explored is how it could ever really work for a whole page.
Because of the complexities of the asp.net page cycle - and the lack of any suitable event that can be utilised AFTER the page html is fully rendered - the only real way for such a system to work is to intercept the HTML as it is rendered by asp.net and apply token replace rules at that stage.
But there are a number of issue with this:
Firstly it does require a change to the dnn core - something like the following code in default.aspx.cs.
The second issue is one of performance - by the time a page is rendered the size of the HTML can be considerable - so it can take time to process thru the HMTL and replace tokens - using a string builder can help here considerably - but it would still be a hit on heavy servers.
And the final issue - is to ensure that the session state does not become corrupted - a token replace on a session state value will mess your page cycle no end.
As a thought bubble the code is a place to start - is it practical - im guessing not for most people.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
protected override void Render (HtmlTextWriter twMaster)
{
if (PortalSettings.UseGlobalTokens)
{
// create a temporary string buider
StringBuilder sbTemp = new StringBuilder();
// define a temporary textwriter and attach the string builder as its IO stream
HtmlTextWriter twTemp = new HtmlTextWriter(newSystem.IO.StringWriter( sbTemp ));
// force ASP.NET to render the page to the temporary textwriter twTemp instead of the default twMaster stream
base.Render( twTemp );
// perform global tokenisation here using the results of sbTemp
GlobalTokenise( sbTemp ):
//Finally output the tokenised string to the default textwriter
twMaster .Write( sbTemp.ToString() );
}
else
{
// just let asp.net do what it normally does if tokens are disabled
base.Render( twMaster );
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
But hey - for what its worth - this is pretty much the code I implemented for a custom site that wanted a lot of global replace type functionality across blogs and articles and other modules and even on the skin and inside containers (dont ask)
Would be interested on other peoples thoughts and ideas on this.
Westa