0

I'm writing a catch-all action method for a 404 page that takes the requested URL, extracts the wordy bits with a regex (\w+)* and sends those bits, space-separated, to the search engine to generate a list of suggested pages.

The problem is, ServerVariables["UNENCODED_URL"] appears to be unavailable here in the Action method. Other server variables are available, however.

I could use ServerVariables["URL"] in conjunction with ServerVariables["QUERY_STRING"], both of which are available. But in some situations this leaves out parts of the URL that might contain valid info regarding the user's intention.

For example, if the mal-formed URL is

/test/007/words/something-with-a-dot.xyz/these-words-are-neglected/?stuff-in-querystring

Then the "URL" and "QUERY_STRING" are found as "/test/007/words/something-with-a-dot.xyz" and "stuff-in-querystring"

"URL" ignores rather bluntly everything after what looks like a file extension. So it doesn't suffice.

So what's up with UNENCODED_URL?
And how can I get its equivalent?

Faust
  • 15,130
  • 9
  • 54
  • 111

1 Answers1

1

Have you tried the HTTP_URL variable? Looks like it returns the raw, encoded URL, for example, "/vdir/default.asp?querystring" - from MSDN.

Source

Also - if you are in a controller's action method, you could(should?) use the HttpContext in place of the SERVER[someProperty]. Something like:

var Url = HttpContext.Request.RawUrl;

which returns the full URL of the current request.

Tommy
  • 39,592
  • 10
  • 90
  • 121
  • That's it! -- HttpContext.Request.RawUrl. BTW, I was trying HttpContext.Request.ServerVariables["UNENCODED_URL"], but kept it short in the post. – Faust Oct 14 '11 at 13:26