I've written a custom rewrite provider using the IRewriteProvider
interface, and installed it in IIS. It's working, but I need to access the content of the request as well as the URL. A newsgroup posting suggests that I should be able to access HttpContext.Current
, but in my testing it shows up as null.
Is there any way to get access to the request content from a rewrite provider?
It's most likely null because it never processed any context. If you'd like to modify the url based on content, you should implement a custom IHttpModule in your application.
http://msdn.microsoft.com/en-us/library/ms972974.aspx
An IHttpModule class for rewriting the URL...
public class UrlRewriteModule : IHttpModule
{
public void Init(HttpApplication context)
{
try
{
context.BeginRequest += new EventHandler(context_BeginRequest);
context.EndRequest += new EventHandler(context_EndRequest);
}
catch (Exception exc)
{
...special logging of exc...
}
}
void context_BeginRequest(object sender, EventArgs e)
{
string fullOrigionalpath = Request.Url.ToString();
Context.RewritePath("...whatever you want...");
}
}
And the web.config...
<configuration>
<system.web>
<httpModules>
<add name="UrlRewriteModule" type="UrlRewriteModule"/>
</httpModules>