2012-03-09 2 views
0

.NET에서 이러한 문자를 이스케이프 처리 할 수있는 방법이 있습니까?. NET에서 이스케이프 문자?

PHP 코드가 포함 된 문자열을 ajax를 통해 .NET 메소드로 보내고 있습니다.

이 방법은 다음 이메일을 통해 전송하지만 그들은 jQuery를 이스케이프 되었기 때문에 것 같습니다 : 나는이 이메일을 통해 전송되기 전에 언 이스케이프 할 필요가

<?php print $test; ?> 

Looks like: 

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

을 그래서 기본적으로.


EDIT 아직도 캔트이 여전히 실 거예요 필드의 내용을 보내 일을 얻는다.

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

답변

2

자바 스크립트 문자열, 또는 .NET에서 URL 디코딩에 해당 (Server.UrlDecode(EncodedString))

+0

답장을 보내 주셔서 감사합니다. 하지만 자바 스크립트에서 decodeURIComponent를 사용하면 Ajax를 통해 .net 메서드로 전송되지 않을까요? 아약스 요청 전에이 문제가 발생했습니다. .NET에서이 작업을 수행해야합니다. 그것을 할 방법을 찾아야합니다. – Robert

+0

친숙한 편집자가 지적한대로'Server.UrlDecode (EncodedString)'을 시도해보십시오. 개인적으로 .Net에 익숙하지 않습니다. –

+0

@Robert 응답에 대한 .NET Framework 디코딩 방법 (System.Web에 포함되어 있음)을 편집했습니다. –

0

URLDecode 그냥 재미로 할 수있는 권리 방법이지만,에 대한 사용 decodeURIComponent 여기에 정규식 한 줄이 있습니다.

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