日期:2014-05-17  浏览次数:21252 次

FCK在MVC和ASP.NET中的配置和使用

FCK在MVC和ASP.NET中的配置和使用

一:FCK配置
1. 下载
FCKeditor_2.6.3.zip(核心文件)
FCKeditor.Net_2.6.3.zip(。Net Control)
(下载地址:FCKeditor 的压缩包
http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor_2.4.3.zip
FCKeditor 的.net 2.0核心库
http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor.Net_2.2.zip)

(或者直接到我的资源http://download.csdn.net/source/1859109中去下载,里面有使用的例子,结合下面内容一看就会)
2. 部署到.NET网站中
FCKeditor_2.6.3.zip解压后将fck根目录改名为fckeditor,放到网站根目录下。
网站根目录下创建一个文件夹uploadfiles,用于存放上传的文件
在网站中引用FCKeditor.Net_2.6.3.zip中的“FredCK.FCKeditorV2.dll”

(注意:在IIS6.0下,上传图片的时候,会出现JS没有权限的错误,解决方法是,更改FredCK.FCKeditorV2.dll的源码,找到 FileBrowser/FileWorkerBase.cs 文件
代码 124 行

Response.Write( @"(function(){var d=document.domain;while (true){try{var A=window.top.opener.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:/.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();" );

把 try 中的 document.domain=d; 删除即可.

然后重新生成 FredCK.FCKeditorV2.dll即可)

3. 简化fck配置
删除所有以_开始的文件和文件夹,在filemanager中的connector中除aspx以外的文件夹

4. 修改fck的语言
fckeditor中的fckconfig.js
61~63行
FCKConfig.AutoDetectLanguage = false ;
FCKConfig.DefaultLanguage = 'zh-cn' ;
FCKConfig.ContentLangDirection = 'ltr' ;

5. 修改上传和浏览文件的程序语言类型
fckeditor中的fckconfig.js
276~277行
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py

6. 上传权限设置
fckeditor2.6.3默认已经在fckconfig.js中允许被授权的连接上传和浏览文件了,但是默认情况下有将所有的连接都设为了未授权状态。修改方法为修改editor/filemanager/connector/aspx/config.ascx

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;
}
找到CheckAuthentication方法,默认情况返回false,这里要改为true。也可以根据登录情况来选择权限检测的返回值。

?

至此,上传设置已经完成!

下面讲一下上传设置的优化(初学者可以不用理会):

1. fckeditor的上传有两种方式:quick方式和非quick方式。
非quick方式是通过单击“浏览服务器”,在“浏览服务器”窗口中上传。这种上传根据上传文件的类型,自动上传到相应的目录,例如图片自动上传到uploadfiles/image下(uploadfiles为用户自己指定);
quick方式则通过在“上传”选项卡中上传。这种上传直接将文件上传到上传根目录uploadfiles。(uploadfiles为用户自己指定)。
但是个人认为quick上传不好的地方在于所有上传的文件不分类型都放在根目录,很凌乱。所以考虑将这两种上传方式都按照类型存放到相应的文件夹中。

修改方法:

方法1:修改filemanager/connectors/aspx/config.ascx

?

TypeConfig["File"].AllowedExtensions = new string[] { "7z", "aiff", "asf", "avi", "bmp", "csv", "doc", "fla", "flv", "gif", "gz", "gzip", "jpeg", "jpg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "ods", "odt", "pdf", "png", "ppt", "pxd", "qt", "ram", "rar", "rm", "rmi", "rmvb", "rtf", "sdc", "sitd", "swf", "sxc", "sxw", "tar", "tgz", "tif", "tiff", "txt", "vsd", "wav", "wma", "wmv", "xls", "xml", "zip" };
TypeConfig["File"].DeniedExtensions = new string[] { };
TypeConfig["File"].FilesPath = "%UserFilesPath%file/";
TypeConfig["File"].FilesAbsolutePath = (UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%file/");
TypeConfig["File"].QuickUploadPath = "%UserFilesPath%file/";
TypeConfig["File"].QuickUploadAbsolutePath = (UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%");
将TypeConfig["File"].QuickUploadPath 的值改为与 TypeConfig["File"].FilesPath相同 = "%UserFilesPath%file/";

方法2:修改FCKeditor.Net_2.6.3源代码(较麻烦)

(1). 将FCKeditor.Net_2.6.3.zip解压缩,打开解压后的工程,修改FileBrowser/FileWorkerBase.cs

protected string ServerMapFolder( string resourceType, string folderPath, bool isQuickUpload )
{
TypeConfig typeConfig = this.Config.TypeConfig[ resourceType ];

// Get the resource type directory.
/*---