2012-03-09 84 views
0

有没有办法在.NET中使用这些字符?.NET转义字符?

我发送一个字符串包含PHP代码通过ajax到.NET方法。

然后,此方法通过电子邮件发送,而是因为他们在jQuery的已经逃脱,它看起来像:

<?php print $test; ?> 

Looks like: 

%3C%3Fphp%0A%0Aprint%20%24test%3B%0A%0A%3F%3E 

所以基本上我需要取消转义它是通过电子邮件发送之前。


编辑

仍然无法得到这个工作,仍然不会发送字段的内容。

public static string CreateSnippet(int processid) 
{ 

    //here we find form values posted to the current page 
    HttpRequest post = HttpContext.Current.Request; 
    string email = post["email"]; 
    string comment = post["comment"]; 
    string name = post["name"]; 
    string website = post["website"]; 

    var DecodedString = HttpContext.Current.Server.UrlDecode(comment); 

    var mailcontent = new StringBuilder(); 
    mailcontent.AppendFormat(EmailLineFormat, "Name", name); 
    mailcontent.AppendFormat(EmailLineFormat, "Email", email); 
    mailcontent.AppendFormat(EmailLineFormat, "Website", website); 
    mailcontent.AppendFormat(EmailLineFormat, "Message", DecodedString); 

    // Send the email 
    library.SendMail("[email protected]", "[email protected]", "Contact Form Enquiry", mailcontent.ToString(), true); 

    //if nothing gets created, we return zero 
    return "success"; 

} 

我是以正确的方式使用它还是存在与我设置变量的方式有关的问题?

感谢 罗伯特

+0

这个称谓使我的突破爆炸。 – Hamish 2012-03-09 00:38:26

回答

2

在JavaScript中的字符串或URL解码的.NET中的等价物(Server.UrlDecode(EncodedString)

+0

感谢您的回复。但如果我在javascript中使用decodeURIComponent它不会通过Ajax发送到.net方法? 这是在ajax请求之前将其转义的原因。 我需要在.NET中完成它。只需要找出实现方法。 – Robert 2012-03-09 00:30:33

+0

尝试'Server.UrlDecode(EncodedString)'作为友好的编辑指出。我个人不熟悉.NET。 – 2012-03-09 00:33:02

+0

@Robert我编辑了答案的.NET解码方法(这包含在System.Web中)。 – 2012-03-09 00:33:09

0

URLDecode是做了正确的方式,但只是为了好玩用decodeURIComponent这里是一个正则表达式单线程:

Regex.Replace(input, "%(..)", m => ((char)Convert.ToInt32(m.Groups[1].ToString(), 16)).ToString());