1、CKEditor原名FckEditor,著名的HTML編輯器,可以在線編輯HTML內容。自己人用CKEditor,網友用UBBEditor。
配置參考文檔,主要將ckeditor中的(adapters、images、lang、plugins、skins、themes、ckeditor.js、config.js、contents.css)解壓到js目錄,然后“顯示所有文件”,將ckeditor的目錄“包含在項目中”,在發帖頁面引用ckeditor.js,然后設置多行文本框的class="ckeditor"(CSS強大)(服務端控件CssClass=" ckeditor ",客戶端控件要設定cols、rows屬性,一般不直接用html控件),代碼中仍然可以通過TextBox控件的Text屬性來訪問編輯器內容。
由于頁面提交的時候asp.net會把富文本編輯器中的html內容當成攻擊內容,因此需要在aspx中的Page標簽中設置 ValidateRequest="false" 來禁用攻擊檢測(2010中還要根據報錯信息修改WebConfig來禁用XSS檢測)。
遇到錯誤如下:

**修改WebConfig來禁用XSS檢測
當asp.net提交“>”這些字符到aspx頁面時,如果沒有在文件頭中加入“ValidateRequest="false"”這句話,就會出現出錯提示:從客戶端(?xml version="...='UTF-8'?>SOAP-ENV:Envelope S...")中檢測到有潛在危險的Request.Form 值。
如你是vs2008的用戶,只要在aspx文件的開始部分,如下文所示處:
復制代碼 代碼如下:
%@ Page Language="C#" CodeBehind="News_add.aspx.cs" Inherits="CKEditor.Default" %>加上ValidateRequest="false" 即可。
但是如果是VS2010,僅僅這樣還是不夠的。還需要雙擊打開web.config,在system.web>/system.web>之間添加下面語句
復制代碼 代碼如下:
pages validateRequest="false" />
httpRuntime requestValidationMode="2.0" />
2、CKFinder是一個CKEditor插件,用來為CKEditor提供文件的上傳的功能。將bin\Release下的CKFinder.dll添加到項目的引用;將core、ckfinder.js、ckfinder.html、config.ascx解壓到CKFinder自己的目錄。按照文檔修改CKEditor的config.js,將上傳的處理程序設定為CKFinder,注意路徑的問題。
復制代碼 代碼如下:
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
//改成ckfinder的絕對路徑,從網站的本目錄開始
var ckfinderPath = "/admin/js";
config.filebrowserBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html';
config.filebrowserImageBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?Type=Images';
config.filebrowserFlashBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?Type=Flash';
config.filebrowserUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUploadtype=Files';
config.filebrowserImageUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUploadtype=Images';
config.filebrowserFlashUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUploadtype=Flash';
};
使用測試,在插入超鏈接、插入圖片、插入文件中都有“上傳”l 因為上傳文件是非常危險的動作,因此在文件上傳的時候會進行權限校驗。在config.ascx的CheckAuthentication方法中校驗是否有權限上傳,返回true表示有權限,否則沒有權限,一般修改成判斷用戶是否登錄,并且登錄用戶是有上傳權限的用戶,可以用Session或者Membership來做。
復制代碼 代碼如下:
public override bool CheckAuthentication()
{
// WARNING : DO NOT simply return "true". By doing so, you are allowing
// "anyone" to upload and list the files in your server. You must implement
// some kind of session validation here. Even something very simple as...
//
// return ( Session[ "IsAuthorized" ] != null (bool)Session[ "IsAuthorized" ] == true );
//
// ... where Session[ "IsAuthorized" ] is set to "true" as soon as the
// user logs on your system.
object obj = Session["已經登錄"] = true;
if (obj!=nullConvert.ToBoolean(obj)==true)
{
return true;
}
else
{
return false;
}
}
思考:如何實現只有指定IP地址的用戶才能上傳?
復制代碼 代碼如下:
if (Request.UserHostAddress == "129.0.0.0.1") { return true; }
在SetConfig函數中設置上傳文件夾的位置BaseUrl、縮略圖的位置,每種類型數據的上傳路徑、允許上傳的文件類型AllowedExtensions等。
您可能感興趣的文章:- asp.net 為FCKeditor開發代碼高亮插件實現代碼
- Asp.net FCKEditor 2.6.3 上傳文件沒有權限解決方法
- FCKeditor ASP.NET 上傳附件研究
- asp.net ckeditor編輯器的使用方法
- ASP.NET中FCKEDITOR在線編輯器的用法
- ASp.net下fckeditor配置圖片上傳最簡單的方法
- asp.net CKEditor和CKFinder的應用
- asp.net+FCKeditor上傳圖片顯示叉叉圖片無法顯示的問題的解決方法
- ASP.NET中CKEditor與CKFinder的配置使用