我想显示一个来自SQLC的字符串。字符串类似于,“Hello演示&我希望”这个字符串在数据库中是最高级的。输出端我只显示"Hello演示&",我想显示完整的字符串"Hello这个演示,我想要“ in C#”
发布于 2011-12-26 06:52:14
我认为出现问题是因为char &您需要在将数据存储到db中之前对其进行编码,并在从db获得数据后对其进行解码。
示例
string value = "Hello This demo & i want that";
// 1. Encode your html before you store it in your db
value = HttpUtility.HtmlEncode(value);
//Now you can store it in your db
//Decode your values from the db before you present it on page.
value = HttpUtility.HtmlDecode(value);我还建议在您将数据存储在db中之前,防止sql注入。
例如,请参阅此函数
protected string Injection(string str)
{
//Checks for remarks, new commands and string inputs.
if (str.Contains("--"))
str.Remove(str.IndexOf('-'), 1);
else if (str.Contains(";"))
str.Remove(str.IndexOf(';'),1);
return str.Replace("'","''");
}你可以增加更多的保护。
我希望它能帮到你
https://stackoverflow.com/questions/8633459
复制相似问题