06/26/2009
Adding HttpModules to Agility Websites? Extend the ExtensibleAgilityHTTPModule
Posted by
Joel Varty
If you want to do Friendly Urls or other things in an Agility website that requires you to add an Http Module, you should do it by extending Agility.Web.HttpModules.ExtensibleAgilityHTTPModule.
This is a module that already has the appropriate logic in it for handling language switching, state management, etc.
There is one method in this class to override called "InitExtensibleModule()" that you can treat like the init of a regular http module. From there, you can bind to the begin request event, or whatever other event you need.
public override void InitExtensibleModule()
{
base.BeginRequest += new EventHandler(FriendlyUrlModule_BeginRequest);
}
void FriendlyUrlModule_BeginRequest(object sender, EventArgs e)
{
}
Also, please take note that if you are doing friendly URLs, you'll need to add some logic to ensure the output cache of the page is a different version for every raw url.
You can usually do this by added Request.RawUrl to the GetVaryByCustomString method as a return value like so:
public override string GetVaryByCustomString(HttpContext context, string custom)
{
//AgilityCacheControl is a special "VaryByCustom" value that is added in the HTTPModule.
if (string.Compare(custom, "AgilityCacheControl", true) == 0)
{
StringBuilder sb = new StringBuilder();
sb.Append(Agility.Web.Data.GetAgilityVaryByCustomString(context));
sb.Append(context.Request.RawUrl);
return sb.ToString();
}
return base.GetVaryByCustomString(context, custom);
}
« Back to Blog
Main Page |