FCKeditor .Net 使用方法

單下載FCKeditor_2.6.3.zip並不能應用.Net環境,還需要下載另外一個文件FCKeditor.Net_2.6.3.zip。官網下載地址:http://www.fckeditor.net/

   下面講講FCKeditor.Net編輯器在.net環境的配置方法。

   第一步:解壓縮FCKeditor_2.6.3.zip文件,並將解壓縮得到的fckeditor文件夾複製到你想使用這個編輯器的網站的根目錄下面。

   第二步:把下載的FCKeditor.Net.zip隨便解壓縮到你硬盤的一個空目錄,裏面是FCKeditor.Net的源代碼,可以對它進行再度開發,我這裏講直接應用,我們要使用到是其目錄下的\bin\Debug目錄中的FredCK.FCKeditorV2.dll文件。在你的網站裏面把這個FredCK.FCKeditorV2.dll添加到bin目錄下。

   第三步:進入FCKeditor文件夾,編輯 fckconfig.js 文件,如下:

 

1、指定編輯器應用的編程環境,修改
var _FileBrowserLanguage = 'asp' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'asp' ; // asp | aspx | cfm | lasso | php
改爲
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | php


2、配置語言包。有英文、繁體中文等,這裏我們使用簡體中文。
修改
FCKConfig.DefaultLanguage = 'en' ;

FCKConfig.DefaultLanguage = 'zh-cn' ;


3、配置皮膚。有default、office2003、silver風格等,這裏我們可以使用默認。
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ;
4、在編輯器域內可以使用Tab鍵。(1爲是,0爲否)
FCKConfig.TabSpaces = 0 ; 改爲FCKConfig.TabSpaces = 1 ;


5、加上幾種我們常用的字體的方法,例如:
修改
FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;

FCKConfig.FontNames = '宋體;黑體;隸書;楷體_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana'


6、編輯器域內默認的顯示字體爲12px,想要修改可以通過修改樣式表來達到要求,打開/editor/css/fck_editorarea.css,修改font-size屬性即可。如font-size: 14px;


7、關於安全性。
如果你的編輯器用在網站前臺的話,那就不得不考慮安全了,在前臺千萬不要使用Default的toolbar,要麼自定義一下功能,要麼就用系統已經定義好的Basic,也就是基本的toolbar,
修改
FCKConfig.ToolbarSets["Basic"] = [
    ['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-','About']

FCKConfig.ToolbarSets["Basic"] = [
['Bold','Italic','-','OrderedList','UnorderedList','-','Unlink','-','Style','FontSize','TextColor','BGColor','-','Smiley','SpecialChar','Replace','Preview']
] ;
   第四步:在Web.Config文件裏面添加,如下所示

1、配置WebConfig,在<appSettings>節點添加,如下所示:
如果你用的是默認的上傳功能,則
    <add key="FCKeditor:BasePath" value="~/fckeditor/"/>
    <add key="FCKeditor:UserFilesPath" value="/網站名稱/UploadFiles/"/>
第五步:在頁面裏應用FCKeditor編輯器

<%@ Page Language="C#" AutoEventWireup="true"   CodeFile="Default.aspx.cs" Inherits="_Default" validateRequest="false" %>

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
// 這裏要主要兩個參數
// 默認爲<%@ Page Language="C#" AutoEventWireup="true"   CodeFile="Default.aspx.cs" Inherits="_Default" %>
// 我們要添加一個參數 validateRequest=false,否則提交帶html代碼的內容會報錯
// 從客戶端(...)中檢測到有潛在危險的 Request.Form 值。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>無標題頁</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server">
        </FCKeditorV2:FCKeditor>
        &nbsp;</div>
    </form>
</body>
</html>
如何獲取其內容呢?讀取FCKeditor1控件的Value屬性值即可。

到這裏基本OK了,但是我發現在使用圖片上傳功能的時候,會彈出一個阻止框,顯示"this connector is disabled Please check the"editor/filemanager/connectors/aspx/config.aspx",解決這個錯誤的方法是打開editor/filemanager/connectors/aspx/config.ascx修改CheckAuthentication()方法,返回true

C# code

private 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 in your system.

        return true;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章