敏感語処理

12244 ワード

1.jsは敏感語が多いがページの実行が遅いため、最後にc#バックグラウンドに置いてフィルタリングを実現する
var words=[' 1',' 2'];
var p=' 1, 2, ';
for(var i=0;i 
  

C# フィルタリング

 public bool  Read(string txt)

    {

            string path = HttpContext.Current.Server.MapPath("~/Filter/Filter.txt");

            Encoding code = Encoding.GetEncoding("gb2312");

            StreamReader sr = new StreamReader(path, code);

            string temp = Regex.Replace(txt, @"[^\u4E00-\u9FA5]", " ");

            string tmepvalue = sr.ReadToEnd();

            sr.Close();

            bool change = false;

            foreach (string s in tmepvalue.Split('|'))

            {

                string ci = s;

 

                if (txt.Contains(ci))

                {

                    temp = Regex.Replace(txt, ci, "**");

                    change = true;

                }

            }

            if (change)

            {

                string errortxt = "    $('.success').hide(); $('.warning').show(); $('.intotit').html(' '); "</span><span style="font-family:' ';font-size:13px;background:rgb(255,255,255);"> +</span></p> <p><span style="font-family:' ';font-size:13px;background:rgb(255,255,255);">             </span><span style="font-family:' ';color:rgb(163,21,21);font-size:13px;background:rgb(255,255,255);">" $('.errorinfo').html(' , ** 。'); $('.showok').show();$('#messages').val('"</span><span style="font-family:' ';font-size:13px;background:rgb(255,255,255);"> + temp + </span><span style="font-family:' ';color:rgb(163,21,21);font-size:13px;background:rgb(255,255,255);">"');";

                Page.ClientScript.RegisterStartupScript(this.GetType(), "AA", errortxt);

                return false;

            }

            return true;

 

    }

//Page.ClientScript.RegisterStartupScript html