views:

487

answers:

3

Hi,

I'm using the Intelligencia UrlRewriter on a project.

It's working fine to rewrite urls typed into the browser.

For example, if I enter

http://localhost/People

This is being correctly rewritten as:

http://localhost/People.aspx

Now, the problem is, when I am in the code behind I need to access the Friendly URL, but Request.ServerVariables seems to only have the unfriendly URL available.

Does anyone know, is there anyway I can access this oringinal, friendly Url in code? Or am I too late?

Thanks in advance!

Am I not clear enough? Ask me and I'll clarify anything!!

A: 

I'm using it and have been for .. er .. 2 years now i think. (Thank gawd IIS7 and MVC are here ! )

anyways, can u check the IIS Server Variables for all of these and tell us what you get...

  1. PATH_INFO
  2. URL
  3. SCRIPT_NAME

eg (this is a snippet of the PATH_INFO for a page i have set up which dumps ALL the request variables) :-

PATH_INFO: [/admin/Miscellaneous.aspx]

and to get it ..

Request.ServerVariables["PATH_INFO"]

Keep us posted.

Pure.Krome
@PureKrome: Hey! Cheers on the quick reply! Request.ServerVariables["PATH_INFO"] unfortunately returns /people.aspx, and I am looking for /People/. But it sounds like you're thinking what I was thinking. So I got all the Server Variables output in the immediate window while Debugging. Then I searched the output for the word "people" but every reference was to people.aspx... making me think the friendly URL is inaccessable via server variables. Of course, I'd love to be proved wrong! Any other ideas?
Ev
A: 

The Intelligencia rewrite rules are stored in the web.config, which is parsable. So you could traverse the rules in the web.config to find a match and use the matched value from there

Obviously this would not work for pattern matching, just explicit rules such as the one in your example

Nick Allen - Tungle139
heavy, but do-able if you really have too. good idea.
Pure.Krome
@Nick: Thanks for the idea mate. Unfortunately I am using patterns in my matches so might be tough. What I'd really like is just some way of getting to the original URL from some .net object... hrmmm... I'm just not even sure if it's possible. By the time I'm trying to get to this in the code, I suspect the info I'm after has been lost in the ether...
Ev
A: 

Got it guys.

@Nick Allen and Pure.Krome: Thanks for the help!!

I found the piece of data in:

HttpContext.Current.Request.RawUrl

If it exists in ServerVariables, I couldn't see it, but in conclusion, the data is there so I won't have to cry myself to sleep :)

Okay. Thanks again!!

Ev
well done. i didn't see this post and had a debug-play with my code and also found that. heh :) well done! u can tick your own answer, in a few days.
Pure.Krome