转换HTML危险字符的代码比如说我在文本框里有写
<script></script>
我提交以后转换成
<script></script>
也就是HTML格式的。过滤字符的方法
<script></script>
我提交以后转换成
<script></script>
也就是HTML格式的。过滤字符的方法
解决方案 »
- 在线等,关于Response.Redirect的问题,多谢
- this.anclass.ClientID这里想取得anclass的Text的内容要怎么写?
- 哪有用vs.net2005做的网站源码,操作数据库的。
- 如何将.asp文件转化为.aspx文件
- 请问谁有手机所属位置的数库啊!!
- 我定义了一个类,在此类的成员函数中,为什么不能使用Response.Write语句?
- 好纠结的问题啊啊啊啊啊!@#@#!
- 菜鸟问题--如何在TEXTAREA中输入文本并保存到数据库中,然后读出来的时候还能显示其格式?
- ASP.NET开发前做技术调查时,值得注意的地方,请大家一起跟贴,完善!!!
- 如何屏蔽单引号?
- 【探讨】如何获取GridView模板列里动态生成的控件
- 送分^_^..VB转C#问题。。
/// <summary>
/// 过滤危险脚本
/// </summary>
/// <param name="htmlCode"></param>
/// <returns></returns>
public string wipeScript(string htmlCode)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\s]", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\s]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\s]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\s]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\s]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
htmlCode = regex1.Replace(htmlCode, ""); //过滤<script></script>标记
htmlCode = regex2.Replace(htmlCode, ""); //过滤href=javascript: (<a>) 属性
htmlCode = regex3.Replace(htmlCode, " _disibledevent="); //过滤其它控件的on...事件
htmlCode = regex4.Replace(htmlCode, ""); //过滤iframe
htmlCode = regex5.Replace(htmlCode, ""); //过滤frameset
return htmlCode;
}
如果只是 转 > 什么的 这个就行
Server.HtmlEncode()