asp.net下使用CKEditor和CKFinder

來源:互聯網
上載者:User
1、下載 ckeditor_3.0.1.zip 並解壓到 ckeditor(在根目錄下)。

官方網站:CKEditor(Fully functional, open source editor, with source code included)

 

CKEditor

2、在 aspx 頁面或者 master 模板頁 <head> 標籤中載入 ckeditor.js:

  <!-- 載入 CKEditor JS 檔案 -->
  <script src="../ckeditor/ckeditor.js" type="text/javascript"></script>

  在<body>標籤中使用ckeditor:

  <!-- 使用 ckeditor 必須定義 class="ckeditor" -->
  <asp:TextBox id="txtContent" class="ckeditor" TextMode="MultiLine" Text='<%# Bind("info") %>' runat="server"></asp:TextBox>

  與其他 .net 控制項使用方法相同,設定 Text='<%# Bind("info") %>' 可以方便與資料來源進行互動。

3、config.js 的自訂

/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or
http://ckeditor.com/license
*/

CKEDITOR.editorConfig = function(config) {

    // Define changes to default configuration here. For example:  
    config.language = 'zh-cn'; //配置語言  
    // config.uiColor = '#FFF'; //背景顏色  
    // config.width = 400; //寬度  
    config.height = 400; //高度
    config.skin = 'v2'; //編輯器樣式

    // 取消 “拖拽以改變尺寸”功能
    config.resize_enabled = false;

    // 基礎工具列
    // config.toolbar = "Basic";
   
    // 全能工具列
    // config.toolbar = "Full";
   
    // 自訂工具列
    config.toolbar =
    [
    ['Source', '-', 'Preview'], ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'], ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'], ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote', 'ShowBlocks'], '/',
    ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'], ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], ['Link', 'Unlink', 'Anchor'], ['Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar'], '/',
    ['Styles', 'Format', 'Font', 'FontSize'], ['TextColor', 'BGColor'], ['Maximize', '-', 'About']
    ];

};

4、要精簡 ckeditor 可以將 _samples、_source 檔案夾刪除,lang 目錄下可以只保留en.js、zh.js、zh-cn.js 三個語言檔案。

5、CKEditor 不具備上傳功能,需要整合 CKFinder 才能實現上傳功能。

CKFinder 與 CKEditor 進行整合的配置方法:

官方網站:CKFinder(powerful and easy to use Ajax file manager for web browsers)

CKFinder for Asp.net

6、下載 ckfinder_aspnet_1.4.1.1.zip 並解壓到 ckfinder(在根目錄下)。

7、將 " \ckfinder\bin\CKFinder.dll " 剪下到根目錄的 Bin 檔案夾中或添加 CKFinder.dll 引用,否則出現如下錯誤:

XML request error: Internal Server Error (500)

Do you want to see more info?

8、開啟 " \ckfinder\config.ascx ",修改 BaseUrl 為 BaseUrl = "~/ckfinder/userfiles/";
  // 注意“~”
  // 以 userfiles 為預設路徑,其目錄下會自動產生images、flash等子目錄。

9、在 ckeditor/config.js 中整合 ckfinder。

  // 自訂 CKEditor 樣式
  CKEDITOR.editorConfig = function(config) {
  ……
  }

  // 在 CKEditor 中整合 CKFinder,注意 ckfinder 的直接選取要正確
  CKFinder.SetupCKEditor(null, '../ckfinder/');

10、破解〔This is the demo version of CKFinder. Click here to visit our web site.〕的注釋資訊:

11、在 aspx 頁面或者 master 模板頁 <head> 標籤中載入 ckfinder.js:

  <!-- 載入 CKFinder JS 檔案 -->
  <script src="../ckfinder/ckfinder.js" type="text/javascript"></script>

  在<body>標籤中使用ckfinder:

  <!-- 使用 ckeditor 必須定義 class="ckeditor" -->
  <asp:TextBox id="txtContent" class="ckeditor" TextMode="MultiLine" Text='<%# Bind("info") %>' runat="server"></asp:TextBox>

  與其他 .net 控制項使用方法相同,設定 Text='<%# Bind("info") %>' 可以方便與資料來源進行互動。

12、可以將 _samples、_source 檔案夾刪除,lang 目錄下可以只保留en.js、zh.js、zh-cn.js 三個語言檔案。

常見錯誤排除方法:

ckfind檔案夾的config.ascx中找到如下語句

癥狀:因為安全原因,檔案不可瀏覽。請聯絡系統管理員並檢查CKFinder設定檔。

語句:
public override bool CheckAuthentication()
{
  reture false;
}

原因:未設定使用者身分識別驗證或者使用者未登入,設定為 reture true;(不進行使用者身分識別驗證)即可。

癥狀:未知錯誤

語句:
public override bool CheckAuthentication()
{
  reture true;
}

原因:設定不進行使用者身分識別驗證,但是 BaseUrl 路徑不對。

////////////////////////////////////******************************************************/////////////////////////////////////

調試頁面,出現“A potentially dangerous Request.Form value was detected from the client",按照經驗,在web.config中增加

<system.web>
<pages validateRequest="false" />
system.web>

還是同樣錯誤,在頁面頭部加入,


還是出錯。

後來終於試著在config.js檔案中添加下面一行:

config.htmlEncodeOutput = true;

OK!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.