views:

74

answers:

3

i, I have the following URL which is successfully handled by an Apache Tomcat application:

http://localhost:8080/ApplicationX/FileY/UpdateDocument(`&lt;add location="somewhere">ContentZ</add>`).xml?VIEW=RAW

For some reason, when I try to handle the same request in IIS with an ASP.NET Http request handler (Class implementing IHttpHandler), I get the 'Bad request' exception and my code is never called. I have applied this patch in the registry (http://support.microsoft.com/kb/826437) to allow the ':' character but it didn't help with regards to the greater and lesser than characters.

Any ways to make this work? Any reasons with it is allowed in Apache but not in IIS?

Cheers.

P.S. I am using IIS 5.1 on a Windows XP workstation with .NET 3.5 SP1.

+4  A: 

Try using character entities to escape those characters?:

http://localhost:8080/ApplicationX/FileY/UpdateDocument(`&amp;lt;add location="somewhere"&gt;ContentZ&lt;/add&gt;`).xml?VIEW=RAW
Michael Burr
+2  A: 

You need to URLencode your URL, if you want to avoid such problems.

    String UrlEncode(String value)
    {
        StringBuilder result = new StringBuilder();

        foreach (char symbol in value)
        {
            if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~".IndexOf(symbol) != -1) result.Append(symbol);
            else result.Append("%u" + String.Format("{0:X4}", (int)symbol));
        }

        return result.ToString();
    }

The above supports unicode, and pretty much everything.

Theofanis Pantelides
This is a more ideal solution.
Meiscooldude
HttpUtility.UrlEncode (and UrlDecode) method works fine too.
BC
Yeah, but I've run into practical problems, especially in oAuth
Theofanis Pantelides
What language is that?
Alexsander Akers
as far as I can tell, this will do the wrong thing for characters beyond the US-ASCII range.
Julian Reschke
Well, it's implemented on a Greek website, successfully
Theofanis Pantelides
A: 

You should replace the < and > signs with &lt; and &gt; as these characters are special characters. Therefore, see the PHP function urlencode (urlencode).

Marius Schulz
< and > would be the escaping for HTML/XML, not URIs.
Julian Reschke
Everything is fine when using urlencode(). I was just not sure what the output was ...
Marius Schulz