Want to follow this site? Here's the RSS feed.

Fundamentals of Themelia - Default Index Redirection

Thursday, July 3, 2008

This documentation has been updated for Themelia Framework 2.0 Beta 3.

Today I would like to introduce an HTTP routing concept of Themelia called default index redirection (or just index redirection). This feature helps me manage my web sites a little better than usual, though it probably won't be that big of a deal to most people. As it stands, though, I personally can't standing having similar files being disorganized all over a folder structure. For example, I have no idea how anyone can put up with having active web forms (web forms being used as web forms) in different folders all over a web site.

Therefore, to help me manage a web site, I like to put my basic web forms in a logical organization structure un the /Page_/ branch and let Themelia do all the URL rewriting. Even then, there's still that pesky default document in the root. Not only does that break my pattern of active web forms, but I still have a page that requires management in the root of my web site. No thanks.

Therefore, Themelia gives the ability to move your default document to another location so all active web forms may live together in peace. This is possible through Themelia's index redirection feature.

To use this feature, set the defaultTarget attribute on the Themelia rewrite element to your true default document. Then, to trick IIS into loading the web site, create a blank file in your root called Default.htm; this also means you will need to add Default.htm as a default document in IIS. The following Themelia configuration snippet demonstrate the setup:

<themelia.web>
  <webDomains defaultTarget="/Page_/Security/Login.aspx">
  </webDomains>
</themelia.web>

To stop the flow of about a million questions, yes, this feature is functionally the same as putting a Service.Transfer("/Pages_/Security/Login.aspx") in your default document. However, this couples configuration directly with your web application. Furthermore, the point of using this default.htm file is to signal to the world that it's not to be used. Otherwise, some intern will come along and add more code to your /default.aspx file. Therefore, in my web sites, the default.htm stands as a big "Go Away" sign containing only the test "This page intentionally left blank."

Internals

The index redirection feature is a prime example of a preprocessor and midprocessor working together. Internally, Themelia runs IndexRedirectPreProcessor::OnPreHttpHandlerExecute to check to see if the request is for the default document and if index redirection is active. This is actually the internal Themelia preprocessor that uses the parameter array as the following snippet shows:

new IndexRedirectPreProcessor().OnPreProcessorExecute(context, midProcessorList);

IndexRedirectPreProcessor will then do a few checks to see if index redirection should occur. If so, IndexRedirectPreProcessor adds IndexRedirectMidProcessor to the midProcessorList parameter so that Themelia will load IndexRedirectMidProcessor when it runs though midprocessors. IndexRedirectPreProcessor also sets two HTTP context items so as to communicate with IndexRedirectMidProcessor and the URLRewriteHttpHandler, one item stating that URL rewriting must occur and the other stating the true index redirection path.

Later when Themelia runs through the various midprocessors, it will run the previously registered IndexRedirectMidProcessor. IndexRedirectMidProcessor then checks to see if IndexRedirectPreProcessor has requested it to start URLRewriting. If so, it returns an instance of UrlRewriteHttpHandler. If you recall, midprocessors have the power to basically skip over the HTTP selection process. In this case, by returning an instance of UrlRewriteHttpHandler to Themelia, IndexRedirectMidProcessor is effectively telling Themelia to run URL rewriting regardless of the HTTP handler selection algorithm or any fallthrough processor (a postprocessor can, however, alter this.)

When the UrlRewriteHttpHandler runs, it checks the other context item set by IndexRedirectPreProcessor to see if an index redirect path was found. If so, the root default document (default.htm) is rewritten to true real default document.

This information should help you to further understand how you may further exploit Themelia's advanced HTTP routing features.

Links

Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License.

Powered by the Minima 3.1 and Squid Micro-Blogging Library.

Built on Themelia Framework 2.0

Developed using NetFXHarmonics DevServer 1.1.

(all of which are NetFXHarmonics products created by David Betz)

Mini-icons are part of the Silk Icons set of icons at famfamfam.com