ASP.NET筆記之CKEditor的使用方法_.Net教程
推薦:ASP.NET筆記之 行命令處理與分頁(yè)詳解本篇文章小編為大家介紹,ASP.NET筆記之 行命令處理與分頁(yè)詳解。需要的朋友參考下
1、CKEditor原名FckEditor,著名的HTML編輯器,可以在線編輯HTML內(nèi)容。自己人用CKEditor,網(wǎng)友用UBBEditor。配置參考文檔,主要將ckeditor中的(adapters、images、lang、plugins、skins、themes、ckeditor.js、config.js、contents.css)解壓到j(luò)s目錄,然后“顯示所有文件”,將ckeditor的目錄“包含在項(xiàng)目中”,在發(fā)帖頁(yè)面引用ckeditor.js,然后設(shè)置多行文本框的class="ckeditor"(CSS強(qiáng)大)(服務(wù)端控件CssClass=" ckeditor ",客戶端控件要設(shè)定cols、rows屬性,一般不直接用html控件),代碼中仍然可以通過(guò)TextBox控件的Text屬性來(lái)訪問(wèn)編輯器內(nèi)容。
由于頁(yè)面提交的時(shí)候asp.net會(huì)把富文本編輯器中的html內(nèi)容當(dāng)成攻擊內(nèi)容,因此需要在aspx中的Page標(biāo)簽中設(shè)置 ValidateRequest="false" 來(lái)禁用攻擊檢測(cè)(2010中還要根據(jù)報(bào)錯(cuò)信息修改WebConfig來(lái)禁用XSS檢測(cè))。
遇到錯(cuò)誤如下:

**修改WebConfig來(lái)禁用XSS檢測(cè)
當(dāng)xml:lang="EN-US">asp.net提交“<>”這些字符到aspx頁(yè)面時(shí),如果沒(méi)有在文件頭中加入“ValidateRequest="false"”這句話,就會(huì)出現(xiàn)出錯(cuò)提示:從客戶端(<?xml version="...='UTF-8'?><SOAP-ENV:Envelope S...")中檢測(cè)到有潛在危險(xiǎn)的Request.Form 值。
如你是vs2008的用戶,只要在aspx文件的開始部分,如下文所示處:
<%@ Page Language="C#" CodeBehind="News_add.aspx.cs" Inherits="CKEditor.Default" %>加上ValidateRequest="false" 即可。
但是如果是VS2010,僅僅這樣還是不夠的。還需要雙擊打開web.config,在<system.web></system.web>之間添加下面語(yǔ)句
<pages validateRequest="false" />
<httpRuntime requestValidationMode="2.0" />
2、CKFinder是一個(gè)CKEditor插件,用來(lái)為CKEditor提供文件的上傳的功能。將bin\Release下的CKFinder.dll添加到項(xiàng)目的引用;將core、ckfinder.js、ckfinder.html、config.ascx解壓到CKFinder自己的目錄。按照文檔修改CKEditor的config.js,將上傳的處理程序設(shè)定為CKFinder,注意路徑的問(wèn)題。
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
//改成ckfinder的絕對(duì)路徑,從網(wǎng)站的本目錄開始
var ckfinderPath = "/admin/js";
config.filebrowserBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html';
config.filebrowserImageBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?Type=Images';
config.filebrowserFlashBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?Type=Flash';
config.filebrowserUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files';
config.filebrowserImageUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images';
config.filebrowserFlashUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash';
};
使用測(cè)試,在插入超鏈接、插入圖片、插入文件中都有“上傳”l 因?yàn)樯蟼魑募欠浅NkU(xiǎn)的動(dòng)作,因此在文件上傳的時(shí)候會(huì)進(jìn)行權(quán)限校驗(yàn)。在config.ascx的CheckAuthentication方法中校驗(yàn)是否有權(quán)限上傳,返回true表示有權(quán)限,否則沒(méi)有權(quán)限,一般修改成判斷用戶是否登錄,并且登錄用戶是有上傳權(quán)限的用戶,可以用Session或者M(jìn)embership來(lái)做。
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.
object obj = Session["已經(jīng)登錄"] = true;
if (obj!=null&Convert.ToBoolean(obj)==true)
{
return true;
}
else
{
return false;
}
}
思考:如何實(shí)現(xiàn)只有指定IP地址的用戶才能上傳?
if (Request.UserHostAddress == "129.0.0.0.1") { return true; }
在SetConfig函數(shù)中設(shè)置上傳文件夾的位置BaseUrl、縮略圖的位置,每種類型數(shù)據(jù)的上傳路徑、允許上傳的文件類型AllowedExtensions等。
分享:ASP.NET筆記之 ListView 與 DropDownList的使用本篇文章小編為大家介紹,ASP.NET筆記之 ListView 與 DropDownList的使用。需要的朋友參考下
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問(wèn)題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(kù)(連接字符串的配置及獲取)
- asp.net頁(yè)面?zhèn)髦禍y(cè)試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過(guò)程實(shí)現(xiàn)分頁(yè)示例代碼
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- AJAX將成為移動(dòng)Web2.0時(shí)代首選開發(fā)平臺(tái)
- .net控件dropdownlist動(dòng)態(tài)綁定數(shù)據(jù)具體過(guò)程分解
- 怎樣處理.NET開發(fā)事件
- 解讀點(diǎn)縮略圖彈出隨圖片大小自動(dòng)調(diào)整的頁(yè)面
- 解讀Asp.net動(dòng)態(tài)生成html頁(yè)面的一種方法
- asp.net2.0 URL重寫以及urlMappings問(wèn)題(1)
- 細(xì)說(shuō).Net開發(fā)中的Visual Basic.Net
- 解讀.Net技術(shù)開發(fā)中兩個(gè)“屬性”引起的歧異
- 解析session簡(jiǎn)要用法實(shí)例
- 如何在GridView數(shù)據(jù)源為空時(shí)也顯示表頭
- 相關(guān)鏈接:
- 教程說(shuō)明:
.Net教程-ASP.NET筆記之CKEditor的使用方法
。