public string LostHTML(string Str)
{
string Re_Str = "";
if (Str != null)
{
if (Str != string.Empty)
{
string Pattern = "<\\/*[^<>]*>";
Re_Str = Regex.Replace(Str, Pattern, "");
}
}
return (Re_Str.Replace("\\r\\n", "")).Replace("\\r", "");
}
{
string Re_Str = "";
if (Str != null)
{
if (Str != string.Empty)
{
string Pattern = "<\\/*[^<>]*>";
Re_Str = Regex.Replace(Str, Pattern, "");
}
}
return (Re_Str.Replace("\\r\\n", "")).Replace("\\r", "");
}
解决方案 »
- 如何判断站点访问者是否是用手机浏览的?
- asp.net c# validation Date format 问题!
- asp.net关于表单提交的问题
- sql表字段 复制
- asp.net中有什么函数可以取字符串中间的某个字符吗?
- Repeater嵌套DataGrid,问题:如何写DataGrid的分页和编辑、删除功能
- 关于datagrid一个小问题?数据库中的bit类型,1:激活2:未激活的显示以及更新问题?
- 關於javascript的問題?(frame之間的copy)
- 怎样用gridview嵌套 dropdownlist来实现更新
- 1000分求一小程序用于学习(希望版住给予支持)。
- 高手请进!!
- .net做论坛管理软件
/// <summary>
/// 过滤html,js,css代码
/// </summary>
/// <param name="html">参数传入</param>
/// <returns></returns>
public static string CheckStr(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", 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(@" no[\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);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
return html;
}
#endregion
HiddenField HTitle = e.Item.FindControl("HFTitle") as HiddenField;
Literal ltTitle = e.Item.FindControl("ltTitle") as Literal;
if (HTitle.Value.Length > 30)
{
ltTitle.Text = HTitle.Value.ToString().PadRight(30).Substring(0,30)+"...";
}
else { ltTitle.Text = HTitle.Value.ToString(); }
我用别人的代码..