URL Encoding - Illegal Character Replacement

Posted by ThePower on Stack Overflow See other posts from Stack Overflow or by ThePower
Published on 2010-12-24T10:41:18Z Indexed on 2010/12/24 10:54 UTC
Read the original article Hit count: 334

Filed under:
|
|
|

Hi,

I am doing some url redirections in a project that I am currently working on. I am new to web development and was wondering what the best practise was to remove any illegal path characters, such as ' ? etc.

I'm hoping I don't have to resort to manually replacing each character with their encoded urls.

I have tried UrlEncode and HTMLEncode, but UrlEncode doesn't cater for the ? and HTMLEncode doesn't cater for '

E.G. If I was to use the following:

Dim name As String = "Dave's gone, why?"
Dim url As String = String.Format("~/books/{0}/{1}/default.aspx", bookID, name)

Response.Redirect(url)

I've tried wrapping url like this:

Dim encodedUrl As String = Server.UrlEncode(url)

And

Dim encodedUrl As String = Server.HTMLEncode(url)

Thanks in advance.

P.S. Happy Christmas

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET