日期:2014-05-19  浏览次数:20943 次

HtmlEncode对HttpResponse编码
如果从   Web   客户端收到的输入在从客户端接收或传递回客户端时未进行验证,则动态生成的   HTML   页可能引发安全风险。嵌入到输入中的恶意脚本(提交到   Web   站点并且随后写回客户端)可以看起来像是来自受信任的源。这称为跨站点脚本攻击。在将接收自客户端的数据从您的站点传送到客户端浏览器时,应总是对其进行验证。

而且,每当将收到的任何输入数据作为   HTML   写出时,都应使用   HtmlEncode   或   UrlEncode   等技术对其进行编码,以防运行恶意脚本。这种技术很适合处理在接收时未经验证的数据。

对数据进行编码或筛选时,必须为   Web   页指定字符集,以便筛选器可识别并移除所有不属于该字符集并可能嵌入了恶意脚本的字节序列(例如非字母数字序列)。———MSDN

我现在的HttpResponse有如下代码:
Response.Write( " <script   language=javascript> ");
Response.Write( "var   parwindow=null; ");
Response.Write( "parwindow=self.opener; ");
Response.Write( "if(parwindow!=null){ "};

Response.Write( "parwindow.document.Form1.txtCustomerNo.value= ' "+   C_info.GetCNo()   +   " '; ");
Response.Write( "parwindow.document.Form1.txtCustomerName.value= ' "+   Transfer(C_info.GetCName())   +   " '; ");
Response.Write( "parwindow.document.Form1.txtCustomerType.value= ' "+   C_info.GetKind()   +   " '; ");

Response.Write( "} ");
Response.Write( "window.opener=null;window.close(); ");
Response.Write( " </script> ");
如何使用HtmlEncode和UrlEncode对其进行编码??


------解决方案--------------------
你给这个编码干什么?UrlEncoder后是以%号做分隔的Unicode数组