开发者

Include dynamic URL in my URL without using query string?

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?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜