我开发了一个博客站点。用户可以发布他们的博客。
用户可以输入javascript、c#、java等代码和html标签如强标签等...
我为了避免 xss,我想替换下面的所有危险字符,但是这个安全性?
WebForm1.aspx.cs:
public partial class WebForm1 : System.Web.UI.Page
{
public string V;
protected void Page_Load(object sender, EventArgs e)
{
V = HtmlEncode("Get content from DB");
}
public string HtmlEncode(string theString)
{
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", " ");
theString = theString.Replace(" ", " ");
theString = theString.Replace("\"", """);
theString = theString.Replace("\'", "'");
theString = theString.Replace("\n", "<br/> ");
..................
..................
...................
return theString;
}
}
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Test.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%=V%>
</div>
</form>
</body>
</html>