admin管理员组文章数量:1356737
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
本文标签: javascriptC URLDecode turns 5C into \ instead of Stack Overflow
版权声明:本文标题:javascript - C# URLDecode turns %5C into \\ instead of- Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744037731a2580088.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论