做网站需要保存文章格式到数据库,你是用什么方法?
Mr_D 2013-01-15 09:43:43 方法一:
1.在web.config中加入如下配置
<httpRuntime requestValidationMode="2.0" />
2.在页面中的page节点中加入ValidateRequest="false",如下所示:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BlogAdd.aspx.cs" Inherits="MessageBoard.BlogAdd" ValidateRequest="false" %>
(这种做法有安全隐患,不过我网上查了大多数都是这么解决)
方法二:
//以二进制格式保存。保存的代码为
02.MemoryStream ms = new MemoryStream();
03.rtbContent.SaveFile(ms, RichTextBoxStreamType.RichText);
04.byte[] bt=ms.ToArray();
05.//将bt保存到数据库
06.//读取的代码为:
07.byte[] bt = (byte[])SqlHelper.ExecuteScalar(sqlStr, null);
08.MemoryStream ms = new MemoryStream(bt, false);
09.rtbContent.LoadFile(ms, RichTextBoxStreamType.RichText);
10.//在SQLServer中对应的数据类型为:image
方法三:替换字符
用这个函数可以解决问题
function displaystr(str)
str=RTrim(str)
if not isnull(str) then
str = replace(str, ">", ">")
str = replace(str, "<", "<")
str = Replace(str, CHR(32), " ")
str = Replace(str, CHR(9), " ")
str = Replace(str, " ", " ")
str = Replace(str, CHR(34), """)
str = Replace(str, CHR(39), "'")
str = Replace(str, vbCr, "")
str = Replace(str, vbLf, "<BR>")
str = Replace(str, vbCrLf, "<BR>")
displaystr = str
else
displaystr="-"
end if
end function
还有最后一种:是“默认禁止,显示允许”。这种内容有点长,就不贴出来了。
如果是你,你用的是那种?