Armstrongest
Armstrongest

Reputation: 15409

How can I encode Quotation marks without Asp.Net complaining?

On my site, an encoded quote (%22) in url path causes "Illegal characters in path" error

I want specify search URLs like so:

www.site.com/search/%22Vitamin+C%22

%22 is an encoded quotation mark "

I'm using a Asp.Net URL Routing and the route is specified like this: "search/{searchTerm}"

When Context["searchTerm"] is retrieved and Decoded, it would result in the above example being: "Vitamin+C" [including quotes]

It would seem that Asp.Net thinks that the there are illegal characters in the URL. I don't understand why, when I AM URLEncoding the text.

How can I encode Quotation marks without Asp.Net complaining? Many people will use quotation marks to group words together and I want to allow this "smart searching"

Upvotes: 0

Views: 1350

Answers (2)

Rob
Rob

Reputation: 3066

Check out the HttpServerUtility.UrlEncode Method

Upvotes: 0

John Sheehan
John Sheehan

Reputation: 78104

For free-form search terms, you should use a QueryString parameter instead of a URL chunk. If you have structured searches (a limited list of categories with names that conform to valid URL requirements or search by zip codes) then you could use the URL structure you are using without issue. You can encode and put whatever you want, including quotes, in the querystring parameter.

Upvotes: 1

Related Questions