R – URL Rewriting in .NET behaves badly with cookieless sessions

cookielessneturl-rewritingurlrewriter.net

I'm currently using Intelligencia's URL Rewriter .NET HTTPModule to rewrite URLs. I am using its Custom Transform feature, which allows me to supply an assembly containing a method that performs the actual URL transform.

I have cookieless sessions turned on, and this is causing some interference with the URL Rewriter.

So, let's say that the path on my server is this :
http://www.foobar.com/actualPath/index.aspx

But I want to use url rewriting to make the path look like this :
http://www.foobar.com/rewrittenPath/index.aspx

I made a script to output the following :
– Request.Url (from my codebehind)
– Request.RawUrl (from my codebehind)
– document.location (from javascript)

I type the following into my address bar :
http://www.foobar.com/rewrittenPath/index.aspx

When I have cookieless sessions disabled, everything works as it should. My script outputs the following values :
– Request.Url shows up as http://www.foobar.com/actualPath/index.aspx
– Request.RawUrl shows up as /rewrittenPath/index.aspx
– document.location shows up as http://www.foobar.com/rewrittenPath/index.aspx
– The URL in the address bar remains unchanged from what I originally typed in.

However, when I have cookieless sessions enabled, things go awry. My script outputs the following values :
– Request.Url shows up as http://www.foobar.com/actualPath/index.aspx
– Request.RawUrl shows up as /actualPath/index.aspx
– document.location shows up as http://www.foobar.com/actualPath/index.aspx
– The URL in the address bar somehow becomes altered, so it shows up as :
http://www.foobar.com/(S(SESSIONID))/actualPath/index.aspx

But this is the strange thing — the OnLoad event for the page only ever fires once. So what is going on here? Is .NET doing a page redirect, but doing it before the OnLoad event has a chance to fire?

What I would like to do is keep the rewrittenPath in the address bar. I would like document.location to return the rewrittenPath. I would like Request.RawUrl to return the rewrittenPath. Is this possible with cookieless sessions? Or does .NET's cookieless session mechanism make this behavior impossible?

Thank you for your time and help.

Best Answer

Cookieless sessions just put the session ID in the URL instead of into a session cookie. Hence, your URL mappings for URLRewriter.NET need to take this behaviour into account. Are you doing this? If you want to be able to run with or without cookies, I would expect you to have rules to match both the cookie and cookieless URL patterns.

Related Topic