最近、不正な書き込み(コメント)が多いので、フィルタ機能をつけました。
1.Dottext.Web.UI.Controls.PostCommentクラス
・btnSubmit_Clickイベント内(// コメントのフィルタ処理記述以降)
2.web.config
・appSettingsセクションへ以下を追加
・value属性に「フィルタ対象の項目:値」を登録して下さい
1.Dottext.Web.UI.Controls.PostCommentクラス
・btnSubmit_Clickイベント内(// コメントのフィルタ処理記述以降)
try { Entry currentEntry = Cacher.GetEntryFromRequest(Context,CacheTime.Short); Entry entry = new Entry(PostType.Comment); if (tbComment.Text.Length > 2000) { throw new ApplicationException( "2000文字を超えるコメントは受け付けられません"); } // コメントのフィルタ処理 foreach (string _keyvalue in ConfigurationSettings. AppSettings["CommentFilter"].ToString().Split(',')) { string _key = _keyvalue.Split(':')[0]; string _value = _keyvalue.Split(':')[1]; string _field; if (_key == "title") { _field = tbTitle.Text; } else { _field = tbUrl.Text; } if (_field.IndexOf(_value) > -1) { throw new ApplicationException("不正URL書き込み"); } }
2.web.config
・appSettingsセクションへ以下を追加
・value属性に「フィルタ対象の項目:値」を登録して下さい
<add key="CommentFilter" value="title:This Good, title:poker, title:texas, titleurl:poker, titleurl:casino, titleurl:pills, titleurl:credit" />
posted @ 21:33 feedback (0)