using System; using System.Web; namespace URLRewriter { /// /// The base class for module rewriting. This class is abstract, and therefore must be derived from. /// /// Provides the essential base functionality for a rewriter using the HttpModule approach. public abstract class BaseModuleRewriter : IHttpModule { /// /// Executes when the module is initialized. /// /// A reference to the HttpApplication object processing this request. /// Wires up the HttpApplication's AuthorizeRequest event to the /// event handler. public virtual void Init(HttpApplication app) { // WARNING! This does not work with Windows authentication! // If you are using Windows authentication, change to app.BeginRequest app.AuthorizeRequest += new EventHandler(this.BaseModuleRewriter_AuthorizeRequest); } public virtual void Dispose() {} /// /// Called when the module's AuthorizeRequest event fires. /// /// This event handler calls the method, passing in the /// RawUrl and HttpApplication passed in via the sender parameter. protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication) sender; Rewrite(app.Request.Path, app); } /// /// The Rewrite method must be overriden. It is where the logic for rewriting an incoming /// URL is performed. /// /// The requested RawUrl. (Includes full path and querystring.) /// The HttpApplication instance. protected abstract void Rewrite(string requestedPath, HttpApplication app); } }