在SQL Server中是不是默认不能添加含HTML代码的数据?如果要添加含HTML代码的数据应该怎么办?
用ASP.NET开发

解决方案 »

  1.   

    HTML转换 /// <summary>
            /// 插入SQL时替换字符
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string Encode(string str)
            {
                str = str.Replace("'", "''");
                str = str.Replace("\"", "&quot;");
                str = str.Replace("<", "&lt;");
                str = str.Replace(">", "&gt;");
                str = str.Replace("\n", "<br>");
                str = str.Replace("“", "&ldquo;");
                str = str.Replace("”", "&rdquo;");
                return str;
            }        /// <summary>
            /// 取SQL值时还原字符
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string Decode(string str)
            {
                str = str.Replace("&rdquo;", "”");
                str = str.Replace("&ldquo;", "“");
                str = str.Replace("<br>", "\n");
                str = str.Replace("&gt;", ">");
                str = str.Replace("&lt;", "<");
                str = str.Replace("&quot;", "\"");
                str = str.Replace("''", "'");
                return str;
            }用这个来替换
      

  2.   

    可以啊,SQL Server字段的话使用text/ntext类型,然后保存的时候就可以保存HTML格式的代码了,网站新闻类型的,包括文字样式、排版、段落及图片等等,都是可以通过文本编辑器实现内容保存到数据库字段中去。xheditorfckeditor
      

  3.   

    我使用的是CKEditor,可以怎么操作?
      

  4.   

    富文本编辑框Fckeditor这种里面有html标签 插入的时候要替换 出来的时候要还原
      

  5.   

    类型是text型就可以,没问题的
      

  6.   

    同意存入数据库都是可以的   读取出来自然就是html了 不用担心  
      

  7.   

    有自带方法转换的。。
    string result2 = HttpUtility.HtmlEncode("html");//将HTML代码转码
    string result= HttpUtility.HtmlDecode("HTML");//将转换后的HTML解码
      

  8.   

    直接存入HTML会不会不安全,出现什么SQL恶意注入什么的?