Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Greater than" and "Lesser than" symbols in URL not working

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

http://localhost:8080/ApplicationX/FileY/UpdateDocument(`<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.

like image 585
jeanml Avatar asked Jun 14 '10 17:06

jeanml


3 Answers

Replace > by %3E

and replace < by %3C

verified and working.

like image 173
AndroidMechanic - Viral Patel Avatar answered Nov 16 '22 00:11

AndroidMechanic - Viral Patel


Try using character entities to escape those characters?:

http://localhost:8080/ApplicationX/FileY/UpdateDocument(`&lt;add location="somewhere"&gt;ContentZ&lt;/add&gt;`).xml?VIEW=RAW
like image 22
Michael Burr Avatar answered Nov 15 '22 23:11

Michael Burr


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.

like image 33
Theofanis Pantelides Avatar answered Nov 16 '22 00:11

Theofanis Pantelides