【转】ASP.NET部署ckeditor_3.6.2及插件ckfinder_aspnet_2.1

本文详细介绍了如何在项目中部署CKEditor和CKFinder插件,实现HTML编辑器功能和文件上传功能,包括部署方法、注意事项及配置细节。

㈠ckeditor 3.6.2:HTML编辑器

部署方法
1、在项目中新建一个ckeditor文件夹
2、解压相应文件夹和文件到ckeditor文件夹,并删除_samples和_source文件夹
3、在需要使用ckeditor控件的页面引用ckeditor.js文件
4、在对应的文本控件(多行文本框)上添加属性:CssClass="ckeditor",即可在浏览器中查看到ckeditor控件的效果

注意:在aspx页面中的Page标签中设置ValidateRequest="false",来禁用RSS攻击检测

 

 


㈡ckfinder_aspnet_2.1
ckeditor插件,用来为ckeditor提供文件的上传功能

部署方法
1、将bin\release下的CKFinder.dll文件解压到项目的DLL文件夹中,并添加引用
2、在项目中新建一个ckfinder文件夹
3、将相应文件夹和文件解压到ckfinder文件夹,并删除_samples和_source文件夹
4、修改ckeditor的config.js文件,在CKEDITOR.editorConfig = function(config) {}函数中,添加如下脚本:

    //-------------------- 外观样式 --------------------//
    config.language = 'zh-cn';  //配置语言
    config.uiColor = '#FFF';    //背景颜色
    config.width = 'auto';      //宽度   
    config.height = '250px';    //高度   
    config.skin = 'office2003'; //界面:v2、kama、office2003
    config.toolbar = 'Full';    //工具栏风格:Full、Basic
    config.font_names = '宋体;楷体_GB2312;新宋体;黑体;隶书;幼圆;微软雅黑;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana'; //字体
    

    //-------------------- 上传路径 --------------------//
    var ckpath = '';  //上级目录,可根据ckfinder的实际目录作相应修改
    config.filebrowserBrowseUrl = ckpath + '/ckfinder/ckfinder.html';                  //上传文件的查看路径
    config.filebrowserImageBrowseUrl = ckpath + '/ckfinder/ckfinder.html?Type=Images'; //上传图片的查看路径
    config.filebrowserFlashBrowseUrl = ckpath + '/ckfinder/ckfinder.html?Type=Flash';  //上传Flash的查看路径

    config.filebrowserUploadUrl = ckpath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files';        //上传文件的保存路径
    config.filebrowserImageUploadUrl = ckpath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'; //上传图片的保存路径
    config.filebrowserFlashUploadUrl = ckpath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash';  //上传Flash的保存路径

5、在config.ascx文件中

⑴修改CheckAuthentication函数,return false修改为return true,当然需要的话可以在return前作自定义验证

    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.

        return false;//修改为:return true; 
    }

⑵修改SetConfig函数,修改BaseUrl默认上传路径

    public override void SetConfig()
    {
        // Paste your license name and key here. If left blank, CKFinder will
        // be fully functional, in Demo Mode.
        LicenseName = "";
        LicenseKey = "";

        // The base URL used to reach files in CKFinder through the browser.
        //BaseUrl = "/ckfinder/userfiles/";//此为默认的BaseUrl上传路径
        BaseUrl = "~/uploader/";//此处为自定义的BaseUrl上传路劲

        // The phisical directory in the server where the file will end up. If
        // blank, CKFinder attempts to resolve BaseUrl.
        BaseDir = "";

        // Optional: enable extra plugins (remember to copy .dll files first).
        Plugins = new string[] {
            // "CKFinder.Plugins.FileEditor, CKFinder_FileEditor",
            // "CKFinder.Plugins.ImageResize, CKFinder_ImageResize",
            // "CKFinder.Plugins.Watermark, CKFinder_Watermark"
        };
        // Settings for extra plugins.
        PluginSettings = new Hashtable();
        PluginSettings.Add("ImageResize_smallThumb", "90x90" );
        PluginSettings.Add("ImageResize_mediumThumb", "120x120" );
        PluginSettings.Add("ImageResize_largeThumb", "180x180" );
        // Name of the watermark image in plugins/watermark folder
        PluginSettings.Add("Watermark_source", "logo.gif" );
        PluginSettings.Add("Watermark_marginRight", "5" );
        PluginSettings.Add("Watermark_marginBottom", "5" );
        PluginSettings.Add("Watermark_quality", "90" );
        PluginSettings.Add("Watermark_transparency", "80" );

        // Thumbnail settings.
        // "Url" is used to reach the thumbnails with the browser, while "Dir"
        // points to the physical location of the thumbnail files in the server.
        Thumbnails.Url = BaseUrl + "_thumbs/";
        if ( BaseDir != "" ) {
            Thumbnails.Dir = BaseDir + "_thumbs/";
        }
        Thumbnails.Enabled = true;
        Thumbnails.DirectAccess = false;
        Thumbnails.MaxWidth = 100;
        Thumbnails.MaxHeight = 100;
        Thumbnails.Quality = 80;

        // Set the maximum size of uploaded images. If an uploaded image is
        // larger, it gets scaled down proportionally. Set to 0 to disable this
        // feature.
        Images.MaxWidth = 1600;
        Images.MaxHeight = 1200;
        Images.Quality = 80;

        // Indicates that the file size (MaxSize) for images must be checked only
        // after scaling them. Otherwise, it is checked right after uploading.
        CheckSizeAfterScaling = true;

        // Due to security issues with Apache modules, it is recommended to leave the
        // following setting enabled. It can be safely disabled on IIS.
        ForceSingleExtension = true;

        // For security, HTML is allowed in the first Kb of data for files having the
        // following extensions only.
        HtmlExtensions = new string[] { "html", "htm", "xml", "js" };

        // Folders to not display in CKFinder, no matter their location. No
        // paths are accepted, only the folder name.
        // The * and ? wildcards are accepted.
        HideFolders = new string[] { ".svn", "CVS" };

        // Files to not display in CKFinder, no matter their location. No
        // paths are accepted, only the file name, including extension.
        // The * and ? wildcards are accepted.
        HideFiles = new string[] { ".*" };

        // Perform additional checks for image files.
        SecureImageUploads = true;

        // The session variable name that CKFinder must use to retrieve the
        // "role" of the current user. The "role" is optional and can be used
        // in the "AccessControl" settings (bellow in this file).
        RoleSessionVar = "CKFinder_UserRole";

        // ACL (Access Control) settings. Used to restrict access or features
        // to specific folders.
        // Several "AccessControl.Add()" calls can be made, which return a
        // single ACL setting object to be configured. All properties settings
        // are optional in that object.
        // Subfolders inherit their default settings from their parents' definitions.
        //
        //    - The "Role" property accepts the special "*" value, which means
        //      "everybody".
        //    - The "ResourceType" attribute accepts the special value "*", which
        //      means "all resource types".
        AccessControl acl = AccessControl.Add();
        acl.Role = "*";
        acl.ResourceType = "*";
        acl.Folder = "/";

        acl.FolderView = true;
        acl.FolderCreate = true;
        acl.FolderRename = true;
        acl.FolderDelete = true;

        acl.FileView = true;
        acl.FileUpload = true;
        acl.FileRename = true;
        acl.FileDelete = true;

        // Resource Type settings.
        // A resource type is nothing more than a way to group files under
        // different paths, each one having different configuration settings.
        // Each resource type name must be unique.
        // When loading CKFinder, the "type" querystring parameter can be used
        // to display a specific type only. If "type" is omitted in the URL,
        // the "DefaultResourceTypes" settings is used (may contain the
        // resource type names separated by a comma). If left empty, all types
        // are loaded.

        DefaultResourceTypes = "";

        ResourceType type;

        type = ResourceType.Add( "Files" );
        type.Url = BaseUrl + "files/";
        type.Dir = BaseDir == "" ? "" : BaseDir + "files/";
        type.MaxSize = 0;
        type.AllowedExtensions = new string[] { "7z", "aiff", "asf", "avi", "bmp", "csv", "doc", "docx", "fla", "flv", "gif", "gz", "gzip", "jpeg", "jpg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "ods", "odt", "pdf", "png", "ppt", "pptx", "pxd", "qt", "ram", "rar", "rm", "rmi", "rmvb", "rtf", "sdc", "sitd", "swf", "sxc", "sxw", "tar", "tgz", "tif", "tiff", "txt", "vsd", "wav", "wma", "wmv", "xls", "xlsx", "zip" };
        type.DeniedExtensions = new string[] { };

        type = ResourceType.Add( "Images" );
        type.Url = BaseUrl + "images/";
        type.Dir = BaseDir == "" ? "" : BaseDir + "images/";
        type.MaxSize = 0;
        type.AllowedExtensions = new string[] { "bmp", "gif", "jpeg", "jpg", "png" };
        type.DeniedExtensions = new string[] { };

        type = ResourceType.Add( "Flash" );
        type.Url = BaseUrl + "flash/";
        type.Dir = BaseDir == "" ? "" : BaseDir + "flash/";
        type.MaxSize = 0;
        type.AllowedExtensions = new string[] { "swf", "flv" };
        type.DeniedExtensions = new string[] { };
    }


6、完成以上步骤,即可在浏览器中使用ckeditor的ckfinder插件的文件上传功能 

【转载】

原文链接:http://www.cnblogs.com/MicoJay/archive/2011/10/10/2206665.html


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值