FCKeditor在.net(asp.net)中的使用方法

安裝前需求:

1.FCKeditor.Net_2.5.zip

下載地址:

http://downloads.sourceforge.net/fckeditor/FCKeditor.Net_2.5.zip

2.FCKeditor_2.6.zip

下載地址:

http://sourceforge.net/project/downloading.php?group_id=75348&filename=FCKeditor_2.6.zip

一、安裝過程:

1、將FCKeditor.Net_2.5.zip解壓縮。我們需要一個DLL文件。在/bin/Release/文件夾下有兩個版本。對應.netframework的版本,我的是.netframework2.0的,就在/bin/Release/2.0/下,拷貝FredCK.FCKeditorV2.dll至你的項目的bin目錄。然後在.net的工具箱中添加此項。

2、將FCKeditor_2.6.zip解壓縮。將所得的fckeditor文件夾拷貝至項目根目錄。打開/fckeditor/fckconfig.js

找到:

var _FileBrowserLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php | py

這兩行,大致位置在271、272兩行。

將這兩行中的PHP替換爲aspx。

找到:

UserFilesPath = "/userfiles/";

這一行,大概在第50行處。將/userfiles/替換爲你的用來存放用戶上傳文件的文件夾。

保存、退出。

3、在/fckeditor/editor/filemanager/connectors/aspx/文件夾下找到config.ascx用editplus或者文本文檔打開,找到:

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 false;
}

這個函數的作用是根據用戶類型判斷用戶是否有上傳文件的權利。如果直接return true;則允許所有用戶上傳文件。建議在這個函數中判斷用戶類型,然後在根據判斷結果來確定返回值。

修改好以後,保存、退出。

4、在你的項目的配置文件:web.config裏找到<appSettings/>將它替換爲:

<appSettings>
<add key="FCKeditor:UserFilesPath" value="/upload/" />
</appSettings>

把 value="/upload/" 替換爲你的用來保存用戶上傳文件的文件夾。

如果web.config裏沒有<appSettings/>這一項,就直接把上面三行代碼放到<configuration>裏面</configuration>

注意:用來保存用戶上傳文件的文件夾必須存在,如果不存在,請自己建立。

5、配置web.config.
打開工程的Web. Config文件,修改appSettings元素,配置如下:

<appSettings>

<add key="FCKeditor:BasePath" value="~/FCKeditor/"/>

<add key="FCKeditor:UserFilesPath" value="/你的項目名稱/uploads" />
//例如:我的解決方案名爲test,那麼這裏就是"/test/uploads".

</appSettings>

設置了FCKeditor:BasePath後就不用再每次使用FCKeditor實例時指定BasePath屬性了,FCKeditor:UserFilesPath則是制定我們所有上傳的文件的所在目錄。你也許會問爲什麼要設置成/test/uploads這樣而不是~/uploads,因爲FCKeditor使用這個值來返回你上傳後的文件的相對路徑到客戶端,~/uploads的形式是ASP.NET在服務可以編譯解釋的,但是在客戶端的靜態就不懂這是什麼了。如果使用~/uploads後,那麼所有上傳文件的返回路徑都是~/uploads形式的,你就會得到這樣的鏈接http://~/uploads/Image/logo.gif這樣的鏈接解果就是路徑爲找到。所以纔要我們上述那樣設置,這是在開發階段,如果在工程完成後發佈時請記住把/test/uploads改成/uploads,道理不說大家也明白,開發階段VS2005在運行項目時的URL是http://localhost/項目名稱/的形式,發佈後在Server上建立站點,跟路徑就是[url]http://www.abc.com/[/url]的形式了,所以發佈後一定要改過來。這些地方是在使用FCKeditor2.6.3+ASP.NET2.0時經常發錯誤而又莫名其所云的地方。

二、使用方法:

可以直接在ASP.NET設計視圖中使用此控件,就像你使用textbox一樣簡單,直接從工具箱拖到頁面上即可。獲取FCKeditor的編輯框中的值,可以用FCKeditor的value屬性獲取編輯框內的值,此數據爲html代碼。至此,整個安裝、使用過程結束!

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