求大哥哥 大姐姐们 我急用 谢谢了
解决方案 »
- Mvc提交按钮不执行controller里方法
- MVC RAZOR模板优点是性能好吗?我现在用ASPX。
- 求好用的asp.net上传控件
- treeview问题帮忙看看
- asp.net 数据采集
- VS2005,在web.config中设置了<roleManager enabled="true" />,可是部署到目标计算机上无法登录系统啊,为什么?我的天!
- 大家好,谁有Infragistics NetAdvantage 2004 最新版本包括实例的?
- 我们公司用上网服务器把上QQ的端口封住了,请问如保设置代理服务器上QQ,或是如何其他的办法上QQ,网页都能上网的就是QQ上不去。,
- document.wrute引用JS的问题?
- 如何在后台创建DataList?求各位大哥帮忙?如何在后台创建DataList?求各位大哥帮忙
- 初学者的困惑
- 如何做到碰到关键字就给其添超链接及其如何调用此方法
在网站后台设置过滤字符
void Application_BeginRequest(object sender, EventArgs e)
{
for (int i=0; i < Request.Form.Count;i++)
{
if (Request.Form[i].ToString() == "__VIEWSTATE") continue;
if (IsM(Request.Form[i].ToString()))
{
Response.Write("您提交的内容中含有非法字符.");
Response.End();
} }
}
protected bool IsM(string InText)
{
string word = @"";
if (InText == null)
return false;
if (Regex.IsMatch(InText,word))
return true;
return false;
}
Regex.Replace
数据库,XML,List都可保存
public static string changeStyle(string contents, DataTable dt)
{
//A标记中title中显示的文本改变样式
string p = "";
//获取到的关键词关联文章总数的记录条数
int kcount = ArticleKeyWordsRules.getArticleCountAll().Rows.Count;
//获取最热关键词的文章数量
double max = Convert.ToDouble(ArticleKeyWordsRules.getArticleCountAll().Rows[0]["ArticleCount"]);
//循环关键词列表
for (int i = 0; i < dt.Rows.Count; i++)
{
string dtkey = dt.Rows[i]["KeyWords"].ToString().Trim();
if (contents.Contains(dtkey))
{
//根据关键词获取对应文章的总数量
int count = ArticleKeyWordsRules.getArticleCountByKeyWords(dtkey);
//取出替换前的关键词
string wordsBefore = dtkey;
//A标记中title显示的文本
p = wordsBefore;
//给A标记的title值进行改变,以免被替换掉
for (int j = 0; j < wordsBefore.Length; j++)
{
//j*5 添加的字符位置,等于后面的字符长度+1
p = p.Insert(j * 5, "|@#|");
}
//获取该关键词的值(绿色=蓝色=值) //double num = (1 - count / (max - min)) * 230;
////把数字转换成int型的
//int number = St.CheckIntTypePageParameterNegative1(num.ToString());
//if (number == -1)
//{
// number = 230;
//}
//int number = Convert.ToInt32(num); double num = (1 - count / max) * 230;
int number = Math.Abs(Convert.ToInt32(num)); //确定该关键词的背景色
string color = "#FF" + DtoX(number) + DtoX(number);
//替换后的样式
string wordsAfter = "<a href=\"ArticleList.aspx?KeyWords=" + HttpContext.Current.Server.UrlEncode(wordsBefore) + "¤tPage=1\" title=\"关 键 词:" + p + " 文章数量:" + count + "\" target=\"_blank\"><span style=\"background-color:" + color + ";\">" + wordsBefore + "</span></a>";
contents = contents.Replace(wordsBefore, wordsAfter);
}
}
//把|@#|替换掉
contents = contents.Replace("|@#|", "");
//返回内容
return contents;
}