As I understand it, javascript is a direct URL encoding a string, while the .net method is not
In fact, they are both wrong!
JavaScript escape() should never be used. Besides the fact that the + code cannot be encoded to %2B , it encodes all non-ASCII characters as a non-standard %uNNNN .
Meanwhile, Server.UrlEncode not exactly the URL encoding as such, but the application/x-www-form-urlencoded encoding, which should normally be used only for query parameters. Using + to represent space outside the form name=value , for example, in part of a path, is incorrect.
This is pretty unfortunate. You can try replacing the character string + %20 after encoding with UrlEncode() when you encode part of the path, not a parameter. In the parameter + and %20 equally good.
source share