views:

55

answers:

2

I want to use the following format of my url:

http://localhost/{url}/{options}/{hash}

But since the url will be very strange with a url inside a url, how would I encode that?

I was thinking of encoding it in hex, since url encoding in .net gave me some strange result that didn't work inside a url. But I don't really know what would be the best way here.

I want to keep the structure of the url, not including any querystring.

+2  A: 

You can use System.Web.HttpUtility.UrlEncode method to encode parts of the url (even another url).

If it's a part of the path and not the query string, UrlPathEncode should do the job.

Thomas Wanner
that only seems to work when using it with a querystring. not with a url-part.
Andreas
you're right, corrected ;)
Thomas Wanner
Will try that right away, thanks. Will mark your answer as solved if it works :)
Andreas
When I tried that it only inserted my url inside the other url, like nothing was changed. (tried but seperate and whole url)Could you give an example on how to use it?
Andreas
A: 

If you don't want the querystring part, then why do you want to encode the url part?

The following url is completely valid:

http://localhost/www.stackoverflow.com/1234/abc

As stated in this RFC, characters, "-" and "." are allowed in a URI.

Zafer
If the url (inside the url) contains a querystring, that won't work.
Andreas
Zafer