C# 如何将html文本发送到ASP.NET通用处理程序?
我的一个表单上有一个WYSIWYG编辑器,我想将编辑器的内容发送到ASP.NET通用处理程序,以便通过Ajax调用进行处理 我在解析收到的html时遇到了一点问题 客户端:C# 如何将html文本发送到ASP.NET通用处理程序?,c#,asp.net,jquery,html-parsing,C#,Asp.net,Jquery,Html Parsing,我的一个表单上有一个WYSIWYG编辑器,我想将编辑器的内容发送到ASP.NET通用处理程序,以便通过Ajax调用进行处理 我在解析收到的html时遇到了一点问题 客户端: $(function(){ $('.send').bind('click', function(event){ var message = $('#TxtMessage').htmlarea('toHtmlString'); message = escape(message);
$(function(){
$('.send').bind('click', function(event){
var message = $('#TxtMessage').htmlarea('toHtmlString');
message = escape(message);
$.get('/Handlers/EmailHandler', { message: message }, function(data){
if( data != null || data != '' )
{
var success = eval(data);
if( success ){
alert('Email sent');
}
}
});
});
});
服务器端:
public class EmailHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string message = (string.IsNullOrEmpty(context.Request.Params["message"]) ? string.Empty : context.Request.Params["message"].ToString());
message = context.Server.HtmlDecode(message);
//do whatever...
}
}
所以问题是,即使在我调用Server.HtmlDecode(string)
时,消息也是乱码
有没有办法解决这个问题 使用
escape()
解析通过JavaScript发送到服务器的字符串的正确方法是使用HttpServerUtility.UrlDecode()