預止XSS攻擊的函式....
protected string GetSafeHtml(object o)
{
if (o != null)
{
string o2 = (string)o;
if (o2.IndexOf("<script",StringComparison.InvariantCultureIgnoreCase) != -1)
{
while (true)
{
int index = o2.IndexOf("<script",
StringComparison.InvariantCultureIgnoreCase);
if (index == -1) break;
o2 = o2.Replace(o2.Substring(index, 8), "<!-- ");
index = o2.IndexOf("</script>",
StringComparison.InvariantCultureIgnoreCase);
o2 = o2.Replace(o2.Substring(index, 9), " !-->");
}
}
return o2;
}
return string.Empty;
}}
private bool DetectInjection(string input)
{
if (input.IndexOf("'") != -1 ||
input.IndexOf("--") != -1 ||
input.IndexOf(" OR ") != -1)
return true;
return false;
}
網頁設計 網路行銷 網路廣告
網頁設計心聲
這是一個發表網頁設計心得的園地 (本站的資訊部份從網上蒐集而來,若侵權,請告知!!)
- Jul 28 Mon 2008 19:09
這是預止XSS攻擊的語法
close
全站熱搜
留言列表