CkEditor文本编辑器配合ckfinder上传功能在.net中的使用步骤

摘要:
E、 g.&lt//t.zoukankan.com/js/ceditor/ceditor.js“type=”text/javascript“>TextBoxCssClass=”ckeditor“TextMode=”MultiLine“runat=”server“&gt,pagesvalidateRequest=”false“>

1.官网下载ckeditor: http://ckeditor.com/download   本文使用Version:CKEditor 3.6.4 for ASP.NET, Released 8 Aug 2012

2.选择_Samples目录下面的ckeditor,删除 CHANGES.html、INSTALL.html、LICENSE.html后,把整个ckeditor复制到网站根目录下面的 js目录下面

3.使用: 引入ckeditor.js文件,在页面添加TextBox服务器文本框,并设置CssClass=”ckeditor” TextMode=”MultiLine”或者使用textarea:如

<script src="http://t.zoukankan.com/js/ckeditor/ckeditor.js" type="text/javascript"></script>
<asp:TextBox CssClass="ckeditor" TextMode="MultiLine"   runat="server"></asp:TextBox>
<textarea   name="_ckeditor" rows="2" cols="20" class="ckeditor"></textarea>

4.至此,就可以看到基本效果了,但是 asp.net默认情况下,不允许提交包含html源代码的表单,这在很大程度上防止了跨站(提交)攻击,但是ckeditor/fckeditor之类的富文本编辑器肯定是要生成html源代码的,因此通常的办法是修改web.config
asp.net2.0/3/3.5时可以这样做:<pages validateRequest="false"></pages>
asp.net4.0,这样还不够,必须写成这样: <pages validateRequest="false"></pages>   <httpRuntimerequestValidationMode="2.0"/>
这样虽然解决了问题,但是同时也降低了安全性,因此使用以下思路:
客户端--表单中增加一个隐藏控件,提交时先把ckeditor的内容用url编码后,赋值给该隐藏控件,然后清空ckeditor的值。
服务端--接收该隐藏控件的值做为ckeditor的内容,同时接收时先url解码。

具体完整代码如下:

javascript部分:

    <script type="text/javascript" src="http://t.zoukankan.com/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="http://t.zoukankan.com/js/ckeditor/ckeditor.js"></script>
    <script type="text/javascript">
        //点击提交时
        function onSubmit(btn) {
            //CKEDITOR.instances.后面为使用classc="keditor"的控件的id
            var editor = CKEDITOR.instances._ckeditor;
            $("#txtContent").val(CKEDITOR.tools.htmlEncode(editor.getData()));
            //清空ckeditor,否则仍然会提示错误
            editor.setData("");
        }
    </script>

html部分:

        <textarea   name="_ckeditor" rows="2" cols="20" class="ckeditor"></textarea>
        <asp:TextBox   Visible="false" runat="server" />
        <asp:Button   Text="提交" OnClientClick="return onSubmit(this);" OnClick="btAdd_Click" runat="server" />

后台取值:

            string s = HttpUtility.HtmlDecode(txtContent.Text.Trim());

此法虽然 绕过了系统默认的安全防御,很容易被提交恶意代码,所以在服务器端还需要进行安全的验证。

6.上传功能

6.1  官网下载CKfinder  http://cksource.com/ckfinder/download   本文使用 ckfinder_aspnet_2.4

6.2  删除CKFinder文件夹中的_source文件夹、 _sample文件夹、changelog.txt、install.txt、license.txt、translations.txt,把整个ckfinder复制到网站根目录下面的 js目录下面

6.3  打开“ckeditorconfig.js”文件,在CKEDITOR.editorConfig = function (config) { 下面添加配置文件

    //使用ckfinder上传功能
    //CKFinder.SetupCKEditor(null, '/js/ckfinder/'); //注意ckfinder的路径对应实际放置的位置
    var dir = "/js";
    config.filebrowserBrowseUrl = dir + '/ckfinder/ckfinder.html'; //上传文件时浏览服务文件夹
    config.filebrowserImageBrowseUrl = dir + '/ckfinder/ckfinder.html?Type=Images'; //上传图片时浏览服务文件夹
    config.filebrowserFlashBrowseUrl = dir + '/ckfinder/ckfinder.html?Type=Flash';  //上传Flash时浏览服务文件夹
    config.filebrowserUploadUrl = dir + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files'; //上传文件按钮(标签)
    config.filebrowserImageUploadUrl = dir + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'; //上传图片按钮(标签)
    config.filebrowserFlashUploadUrl = dir + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash'; //上传Flash按钮(标签)

版权声明:本文为博主原创文章,未经博主允许不得转载。

免责声明:文章转载自《CkEditor文本编辑器配合ckfinder上传功能在.net中的使用步骤》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Bing Maps进阶系列三:使用地图图像服务(ImageryService)北洋大讲堂之“斯凯网络CEO宋涛我的创业之路”感想下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

一篇文章带你了解SVG 蒙版(Mask)

SVG蒙版功能可将蒙版应用于SVG形状。蒙版可确定SVG形状的哪些部分可见,以及具有什么透明度。运行效果可以将SVG蒙版视为剪切路径的更高级版本。 一、简单的蒙版 代码解析: 本示例使用ID=mask1定义一个蒙版。 元素内部是一个元素。元素定义了蒙版的形状。 定义了一个使用mask的元素,元素使用CSS style属性mask内部引用mask ID属性。...

解决jQuery多个版本,与其他js库冲突方法

jQuery多个版本或和其他js库冲突主要是常用的$符号的问题,这个问题 jquery早早就有给我们预留处理方法了,下面一起来看看解决办法。 1.同一页面jQuery多个版本或冲突解决方法。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="...

.net core 3.1

一、安装选择预发行版  配置代码 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNet...

日志服务:NLog

ylbtech-日志服务:NLog NLog是一个基于.NET平台编写的类库,我们可以使用NLog在应用程序中添加极为完善的跟踪调试代码。 NLog是一个简单灵活的.NET日志记录类库。通过使用NLog,我们可以在任何一种.NET语言中输出带有上下文的(contextual information)调试诊断信息,根据喜好配置其表现样式之后发送到一个或多个输...

Metasploit Meterpreter持久后门服务:persistence

原文:https://www.fujieace.com/metasploit/meterpreter-service.html 了解Metasploit Meterpreter 在经历了exploit系统的所有艰苦工作之后,为自己留下更简单的方法回到系统供以后使用通常是一个好主意。这样,如果您最初exploit的服务已关闭或打补丁,您仍然可以访问系统。Me...

idea常用配置

idea 下载其他版本: https://www.jetbrains.com/idea/download/other.html Tomcat配置VM Options:  -XX:PermSize=512m -XX:MaxPermSize=1024m 1.IDEA卡顿,修改IDEA使用内存 修改idea配置文件 在IDEA的安装目录下的bin目录下: 用记事...