ASP.NET筆記之CKEditor的使用方法
配置參考文檔,主要將ckeditor中的(adapters、images、lang、plugins、skins、themes、ckeditor.js、config.js、contents.css)解壓到j(luò)s目錄,然后“顯示所有文件”,將ckeditor的目錄“包含在項(xiàng)目中”,在發(fā)帖頁面引用ckeditor.js,然后設(shè)置多行文本框的class="ckeditor"(CSS強(qiáng)大)(服務(wù)端控件CssClass=" ckeditor ",客戶端控件要設(shè)定cols、rows屬性,一般不直接用html控件),代碼中仍然可以通過TextBox控件的Text屬性來訪問編輯器內(nèi)容。
由于頁面提交的時(shí)候asp.net會(huì)把富文本編輯器中的html內(nèi)容當(dāng)成攻擊內(nèi)容,因此需要在aspx中的Page標(biāo)簽中設(shè)置 ValidateRequest="false" 來禁用攻擊檢測(cè)(2010中還要根據(jù)報(bào)錯(cuò)信息修改WebConfig來禁用XSS檢測(cè))。
遇到錯(cuò)誤如下:
**修改WebConfig來禁用XSS檢測(cè)
當(dāng)asp.net提交“<>”這些字符到aspx頁面時(shí),如果沒有在文件頭中加入“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>之間添加下面語句
<pages validateRequest="false" />
<httpRuntime requestValidationMode="2.0" />
2、CKFinder是一個(gè)CKEditor插件,用來為CKEditor提供文件的上傳的功能。將bin\Release下的CKFinder.dll添加到項(xiàng)目的引用;將core、ckfinder.js、ckfinder.html、config.ascx解壓到CKFinder自己的目錄。按照文檔修改CKEditor的config.js,將上傳的處理程序設(shè)定為CKFinder,注意路徑的問題。
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)限,否則沒有權(quán)限,一般修改成判斷用戶是否登錄,并且登錄用戶是有上傳權(quán)限的用戶,可以用Session或者M(jìn)embership來做。
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等。
相關(guān)文章
asp.net url傳遞后地址欄亂碼(中文超過兩個(gè)漢字)
asp.net 頁面?zhèn)髦形某^兩個(gè)漢字后面就亂碼,編碼編好的url是正確的,可傳到另一個(gè)頁面就會(huì)出錯(cuò),在地址欄就已經(jīng)亂碼了,本文介紹詳細(xì)的解決方法,感興趣的朋友可以了解下,或許對(duì)你學(xué)習(xí)asp.net有所幫助2013-02-02ASP.NET SignaiR 實(shí)現(xiàn)消息的即時(shí)推送,并使用Push.js實(shí)現(xiàn)通知的示例代碼
ASP.NET SignalR 是為 ASP.NET 開發(fā)人員提供的一個(gè)庫,可以簡(jiǎn)化開發(fā)人員將實(shí)時(shí) Web 功能添加到應(yīng)用程序的過程。有興趣的可以了解一下。2017-01-01.net c# gif動(dòng)畫如何添加圖片水印實(shí)現(xiàn)思路及代碼
本文將詳細(xì)介紹下c#實(shí)現(xiàn)gif動(dòng)畫添加圖片水印,思路很清晰,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03ASP.NET生成eurl.axd Http異常錯(cuò)誤的處理方法
在IIS6中同時(shí)啟用了ASP.NET 2.0 和 ASP.NET 4.0 后,網(wǎng)站程序可能會(huì)出現(xiàn)如下錯(cuò)誤:“ System.Web.HttpException: Path ‘//eurl.axd/‘ was not found. ”2011-05-05WEB在模態(tài)窗體里導(dǎo)出或下載文件功能代碼
實(shí)現(xiàn)在模態(tài)窗體里導(dǎo)出或下載文件,具體功能代碼如下,感興趣的朋友可以參考下哈2013-06-06