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

13,781

Solution 1

Replace > by %3E

and replace < by %3C

verified and working.

Solution 2

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

Solution 3

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.

Share:
13,781
Volodymyr Manilo
Author by

Volodymyr Manilo

Updated on June 07, 2022

Comments

  • Volodymyr Manilo
    Volodymyr Manilo almost 2 years

    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.