views:

31

answers:

1

ASP.NET 3.5, IIS7

In my Global.asax's Application_BeginRequest, I need to extract from the request's URL an entirely seperate URL that's been embedded in it without using query string.

The solution I came up with was to hex-encode the entire target URL as if it were a directory, as follows:

http://localhost/687474703A...etc...732E6D7033/irrelevantFilename.txt

This fails for IIS7, whose ASP.NET implementation won't tolerate a URL path greater than 260 characters.

My code controls how the request URL gets generated, and how it might embed the target URL in there, but it doesn't have any control over that target URL value (they're third-party URLs).

How better could I embed this target URL in my request URL?

+2  A: 

You could URL-encode it, or alternatively base-64 encode it. Both are generally more compact than hex encoding.

Note: If the URL is longer than about 200 characters, that 260 character limit will be a problem no matter what. And if the URL is longer than 260 characters... well, you can do the math :-)

I don't quite understand why you even need a separate file afterwards, though. You could use a 404 handler, or just parse right ahead for each request.

Btw: if you have the option, you're probably better off embedding the URL using a cookie, or as a POST argument. If that's not an option, you can also consider using an URL-shortening service like http://bit.ly/ etc. Those URLs are really short. It all depends on where the URLs come from in the first place. If you have control over the generation of these URLs, why not just give them each a short ID, and store them in a table, and look them up when you "parse" the URL?

Jon Watte
The client is a podcatcher (I don't know which), so no cookies or POST, and it will need a filename to display. UrlEncode and Base64 both generate characters invalid for a URL w/o a querystring? The "short ID" idea is a good one, but I'd hoped to avoid it, as this webapp otherwise has no need for a datastore. Ahh... perhaps I could use an API to a bitly-type service for persisting the long URLs ID'd in my URLs...
lance
I finally solved my problem, using a URL-shortening service API to persist the embedded URLs.
lance