Url Rewriting with Filter.NET?

Jan 23, 2008 at 7:58 PM
Is it possible to use Filter.NET as a Url Rewriter? I was looking into some common practices using an HttpModule as part of the pipeline of my ASP.NET application. However, I think need something a little more side-effect free, something that changes the Url before reaching my application. Would I subscribe to the PreProcHeaders event and make the changes there?

I'm looking to use Filter.NET because I'd rather write managed code to access the configuration database, verses tweaking code like IonicIsapiRewriter. My skills in C are a little rusty...

Thank you for any input/advice!
Jan 25, 2008 at 6:52 PM
I added a handler for the UrlMap event, where I modify the e.Context.MappedPath property.

It's odd, the request for the aspx page comes through, the path is modified, but the page for the original url is returned. However, I'm doing just a blanket rewrite of the physical path for all requests and the requests for the css/etc return a 404 as those actually try to pull from the new physical path.

Changing the MappedPath property seems akin to HttpContext.RewritePath, am I way off on this one?
Jan 25, 2008 at 6:52 PM
Edited Jan 28, 2008 at 9:21 PM
So it seems to be side effect free when in the PreProcHeaders event you change the e.Context.Url property. The application continues to function properly, and the relative urls in the app keep the address bar looking as you want it...

Okay, maybe I just tricked myself into thinking this...

Sure did...

Maybe I need to change the Url back on ResponseHeadersEvent?
Jan 30, 2008 at 2:22 PM
Hi Matt,

Changing a URL, much like a URL rewriter, is as simple as subscribing to PreProcHeaders and changing the Url in e.Context.Url. When you do this, you are in fact changing the url of the Http Request. No need to touch the Http Response.

When developing the samples of Filter.NET, I even thought about creating a URL Rewriter using built-in .NET RegExp. Its amazing how simple that is with this framework, and I'm sure someone will sooner or later do exactly that.

Tiago Halm
Feb 6, 2008 at 7:01 PM
Hmm...I must be missing something. I'm setting e.Context.Url inside the PreProcHeaders event handler, but it has absolutely no effect.

Help! :)
Feb 7, 2008 at 1:41 PM
Whoops, disregard that. Just a little misunderstanding on my part.