ASP.NET 學習筆記_12 CKEditor

來源:互聯網
上載者:User

     1、CKEditor原名FckEditor,著名的HTML編輯器,可以線上編輯HTML內容。自己人用CKEditor,網友用UBBEditor。

     配置參考文檔,主要將ckeditor中的(adapters、images、lang、plugins、skins、themes、ckeditor.js、config.js、contents.css)解壓到js目錄,然後“顯示所有檔案”,將ckeditor的目錄“包含在項目中”,在發帖頁面引用ckeditor.js,然後設定多行文字框的class="ckeditor"(CSS強大)(服務端控制項CssClass=" ckeditor ",用戶端控制項要設定cols、rows屬性,一般不直接用html控制項),代碼中仍然可以通過TextBox控制項的Text屬性來訪問編輯器內容。

      由於頁面提交的時候asp.net會把富文字編輯器中的html內容當成攻擊內容,因此需要在aspx中的Page標籤中設定 ValidateRequest="false" 來禁用攻擊檢測(2010中還要根據報錯資訊修改WebConfig來禁用XSS檢測)。

       遇到錯誤如下:

    

      **修改WebConfig來禁用XSS檢測

當asp.net提交“<>”這些字元到aspx頁面時,如果沒有在檔案頭中加入“ValidateRequest="false"”這句話,就會出現出錯提示:從用戶端(<?xml version="...='UTF-8'?><SOAP-ENV:Envelope S...")中檢測到有潛在危險的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是一個CKEditor外掛程式,用來為CKEditor提供檔案的上傳的功能。將bin\Release下的CKFinder.dll添加到項目的引用;將core、ckfinder.js、ckfinder.html、config.ascx解壓到CKFinder自己的目錄。按照文檔修改CKEditor的config.js,將上傳的處理常式設定為CKFinder,注意路徑的問題。

 1 CKEDITOR.editorConfig = function( config ) 2 { 3     // Define changes to default configuration here. For example: 4     // config.language = 'fr'; 5     // config.uiColor = '#AADC6E'; 6  7     //改成ckfinder的絕對路徑,從網站的本目錄開始 8     var ckfinderPath = "/admin/js"; 9     config.filebrowserBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html';10     config.filebrowserImageBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?Type=Images';11     config.filebrowserFlashBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?Type=Flash';12     config.filebrowserUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files';13     config.filebrowserImageUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images';14     config.filebrowserFlashUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash';15 };

      使用測試,在插入超連結、插入圖片、插入檔案中都有“上傳”l 因為上傳檔案是非常危險的動作,因此在檔案上傳的時候會進行許可權校正。在config.ascx的CheckAuthentication方法中校正是否有許可權上傳,返回true表示有許可權,否則沒有許可權,一般修改成判斷使用者是否登入,並且登入使用者是有上傳許可權的使用者,可以用Session或者Membership來做。

 1 public override bool CheckAuthentication() 2     { 3         // WARNING : DO NOT simply return "true". By doing so, you are allowing 4         // "anyone" to upload and list the files in your server. You must implement 5         // some kind of session validation here. Even something very simple as... 6         // 7         //        return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true ); 8         // 9         // ... where Session[ "IsAuthorized" ] is set to "true" as soon as the10         // user logs on your system.11         object obj = Session["已經登入"] = true;12         if (obj!=null&Convert.ToBoolean(obj)==true)13         {14             return true;15         }16         else17         {18         return false;19         }20     }

思考:如何?只有指定IP地址的使用者才能上傳?

        if (Request.UserHostAddress == "129.0.0.0.1") { return true; }

       在SetConfig函數中設定上傳檔案夾的位置BaseUrl、縮圖的位置,每種類型資料的上傳路徑、允許上傳的檔案類型AllowedExtensions等。

 

相關關鍵詞:
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.