I have a web service method that takes a network login (string) as a parameter. The login is URL Encoded from JavaScript so the DOMAIN\USERNAME is encoded into DOMAIN%5CUSERNAME. When I use the HttpUtility.URLDecode on the string, it escapes the backslash and gives me DOMAIN\\USERNAME. I'm attempting to pass this into a profile provider (which expects just a single backslash) and am getting nothing.
I've attempted to do string.Replace() as well as RegEx.Replace() and can't seem to get rid of the 2nd backslash.
Does anyone know a way to resolve this? For now, this is just a proof of concept since I'm working on since I'm not a fan of the network username being posted as a parameter; however, I am still curious to know a way around this issue. Is there a different encoding scheme I can/should use on the JavaScript side if I can't resolve this from C#?
I have a web service method that takes a network login (string) as a parameter. The login is URL Encoded from JavaScript so the DOMAIN\USERNAME is encoded into DOMAIN%5CUSERNAME. When I use the HttpUtility.URLDecode on the string, it escapes the backslash and gives me DOMAIN\\USERNAME. I'm attempting to pass this into a profile provider (which expects just a single backslash) and am getting nothing.
I've attempted to do string.Replace() as well as RegEx.Replace() and can't seem to get rid of the 2nd backslash.
Does anyone know a way to resolve this? For now, this is just a proof of concept since I'm working on since I'm not a fan of the network username being posted as a parameter; however, I am still curious to know a way around this issue. Is there a different encoding scheme I can/should use on the JavaScript side if I can't resolve this from C#?
Share Improve this question edited Mar 3, 2009 at 22:20 Joel Coehoorn 417k114 gold badges578 silver badges813 bronze badges asked Mar 3, 2009 at 22:18 JamesEggersJamesEggers 12.9k14 gold badges65 silver badges89 bronze badges1 Answer
Reset to default 8It doesn't actually turn it into \\
. That's just how it looks under the debugger. The debugger shows you the string literal you'd have to use if you wanted to put it in code. If you print the string out to the console you'll see it's fine.
using System;
using System.Web;
class Test
{
static void Main()
{
string url = "DOMAIN%5CUSERNAME";
string decoded = HttpUtility.UrlDecode(url);
Console.WriteLine(decoded);
}
}
Output:
DOMAIN\USERNAME