views:

507

answers:

1

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.

+1  A: 

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.

Vinay Sajip
Well, my URL mapping is really accepting and shouldn't affect URL rewriting. What appears to be happening is that .NET isn't just sticking the session ID into the URL. It's also doing some kind of page redirect to the 'actual' path (not the rewritten or 'raw' path.) This causes the 'actual' path to appear in the address bar, and it causes JavaScript to have the 'actual' path inside document.location. I would like it if .NET just stuck the session ID into the 'raw' path without redirecting from the 'raw' path to the 'actual' path. Do you know if this is possible?
oops - I said "Well, my URL mapping is really accepting and shouldn't affect URL rewriting." What I meant to say was "my URL mapping is really accepting and should affect cookieless sessions."For the sake of completeness, here is my mapping :<rewrite url="([^\.]+\.aspx.*)" to="${UrlRewriter($1)}" />I'm also using Helicon's ISAPI_Rewrite (lite) to re-route extensionless URLs, and my rewrite directives are thus :RewriteRule ^([^\.]+[^/])$ $1/index.aspx [NC, L]RewriteRule ^([^\.]+/)$ $1/index.aspx [NC, L]