zoukankan      html  css  js  c++  java
  • 让FCKeditor支持多用户环境(asp.net)

      在开发用户管理功能时通常遇到这样一种情况:不同用户上传的图片等文件需要彼此隔离,也就是说每个用户在服务器上需要有一个单独的文件夹用于文件或图片存储。

      目前用的最多的html编辑器要属FCKeditor。下面以.net版本为例,我介绍一下如何实现以上功能。

      我使用的FCKeditor服务器版本为FCKeditor.Net_2.6.3 客户端版本为FCKeditor_2.6.4.1。FCKeditor的配置非常简单请参考        http://www.cnblogs.com/AlexCheng/archive/2009/08/18/1548701.html

      第一步配置web.config文件在<appSettings></appSettings>之间加入

      

     

    <!--FCKedit配置-->
        
    <!--是否开启多用户支持-->
        
    <add key="FCKeditor:MultiUser" value="true"/>
            
    <add key="FCKeditor:BasePath" value="/webuser/fckeditor/"/>
        
    <!--多用户存储路径:/webuser/userfiles/+Session["uid"].ToString()+"/"-->
        
    <add key="FCKeditor:MultiUserPath" value="/webuser/userfiles/"/>
        
    <!--Session["uid"]过期或未设置-->
    <add key
    ="FCKeditor:UserFilesPath" value="/webuser/userfiles/temp/"/>

        找到FCKeditor客户端/fckeditor/editor/filemanager/connectors/aspx/config.ascx 打开

    代码
      1 <%@ Control Language="C#" EnableViewState="false" AutoEventWireup="false" Inherits="FredCK.FCKeditorV2.FileBrowser.Config" %>
      2 <%--
      3  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
      4  * Copyright (C) 2003-2009 Frederico Caldeira Knabben
      5  *
      6  * == BEGIN LICENSE ==
      7  *
      8  * Licensed under the terms of any of the following licenses at your
      9  * choice:
     10  *
     11  *  - GNU General Public License Version 2 or later (the "GPL")
     12  *    http://www.gnu.org/licenses/gpl.html
     13  *
     14  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
     15  *    http://www.gnu.org/licenses/lgpl.html
     16  *
     17  *  - Mozilla Public License Version 1.1 or later (the "MPL")
     18  *    http://www.mozilla.org/MPL/MPL-1.1.html
     19  *
     20  * == END LICENSE ==
     21  *
     22  * Configuration file for the File Browser Connector for ASP.NET.
     23 --%>
     24 <script runat="server">
     25 
     26     /**
     27      * This function must check the user session to be sure that he/she is
     28      * authorized to upload and access files in the File Browser.
     29      */
     30     private bool CheckAuthentication()
     31     {
     32         // WARNING : DO NOT simply return "true". By doing so, you are allowing
     33         // "anyone" to upload and list the files in your server. You must implement
     34         // some kind of session validation here. Even something very simple as...
     35         //
     36         //        return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true );
     37         //
     38         // ... where Session[ "IsAuthorized" ] is set to "true" as soon as the
     39         // user logs in your system.
     40 
     41         return true;
     42     }
     43 
     44     public override void SetConfig()
     45     {
     46         // SECURITY: You must explicitly enable this "connector". (Set it to "true").
     47         Enabled = CheckAuthentication();
     48         if (System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:MultiUser"== "true")
     49         {
     50 
     51             if (HttpContext.Current.Session["uid"]!=null)
     52             {
     53                 UserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:MultiUserPath"+ HttpContext.Current.Session["uid"+ "/";
     54                 Session["FCKeditor:UserFilesPath"= UserFilesPath;
     55             }
     56             else
     57             {
     58                 UserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"];
     59                 Session["FCKeditor:UserFilesPath"= UserFilesPath;
     60             }
     61         }
     62         else
     63         {
     64             UserFilesPath = "/Upload/";
     65         }
     66         // URL path to user files.
     67         //UserFilesPath = "/Upload/";
     68 
     69         // The connector tries to resolve the above UserFilesPath automatically.
     70         // Use the following setting it you prefer to explicitely specify the
     71         // absolute path. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
     72         // Attention: The above 'UserFilesPath' URL must point to the same directory.
     73         UserFilesAbsolutePath = "";
     74 
     75         // Due to security issues with Apache modules, it is recommended to leave the
     76         // following setting enabled.
     77         ForceSingleExtension = true;
     78 
     79         // Allowed Resource Types
     80         AllowedTypes = new string[] { "File""Image""Flash""Media" };
     81 
     82         // For security, HTML is allowed in the first Kb of data for files having the
     83         // following extensions only.
     84         HtmlExtensions = new string[] { "html""htm""xml""xsd""txt""js" };
     85 
     86         TypeConfig[ "File" ].AllowedExtensions            = new string[] { "7z""aiff""asf""avi""bmp""csv""doc""fla""flv""gif""gz""gzip""jpeg""jpg""mid""mov""mp3""mp4""mpc""mpeg""mpg""ods""odt""pdf""png""ppt""pxd""qt""ram""rar""rm""rmi""rmvb""rtf""sdc""sitd""swf""sxc""sxw""tar""tgz""tif""tiff""txt""vsd""wav""wma""wmv""xls""xml""zip" };
     87         TypeConfig[ "File" ].DeniedExtensions            = new string[] { };
     88         TypeConfig[ "File" ].FilesPath                    = "%UserFilesPath%file/";
     89         TypeConfig[ "File" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%file/" );
     90         TypeConfig[ "File" ].QuickUploadPath            = "%UserFilesPath%";
     91         TypeConfig[ "File" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
     92 
     93         TypeConfig[ "Image" ].AllowedExtensions            = new string[] { "bmp""gif""jpeg""jpg""png" };
     94         TypeConfig[ "Image" ].DeniedExtensions            = new string[] { };
     95         TypeConfig[ "Image" ].FilesPath                    = "%UserFilesPath%image/";
     96         TypeConfig[ "Image" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%image/" );
     97         TypeConfig[ "Image" ].QuickUploadPath            = "%UserFilesPath%";
     98         TypeConfig[ "Image" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
     99 
    100         TypeConfig[ "Flash" ].AllowedExtensions            = new string[] { "swf""flv" };
    101         TypeConfig[ "Flash" ].DeniedExtensions            = new string[] { };
    102         TypeConfig[ "Flash" ].FilesPath                    = "%UserFilesPath%flash/";
    103         TypeConfig[ "Flash" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%flash/" );
    104         TypeConfig[ "Flash" ].QuickUploadPath            = "%UserFilesPath%";
    105         TypeConfig[ "Flash" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
    106 
    107         TypeConfig[ "Media" ].AllowedExtensions            = new string[] { "aiff""asf""avi""bmp""fla""flv""gif""jpeg""jpg""mid""mov""mp3""mp4""mpc""mpeg""mpg""png""qt""ram""rm""rmi""rmvb""swf""tif""tiff""wav""wma""wmv" };
    108         TypeConfig[ "Media" ].DeniedExtensions            = new string[] { };
    109         TypeConfig[ "Media" ].FilesPath                    = "%UserFilesPath%media/";
    110         TypeConfig[ "Media" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%media/" );
    111         TypeConfig[ "Media" ].QuickUploadPath            = "%UserFilesPath%";
    112         TypeConfig[ "Media" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
    113     }
    114 
    115 </script>
    116 

     第四步,在用户登录时给Session["uid"]赋值

    这样遍可实现FCKeditor多用户功能。

  • 相关阅读:
    php中的_GET和_POST
    CSS中的特殊符号
    Nginx简介
    php获得时间
    php中定义类
    AcWing 803. 区间合并
    AcWing 826. 单链表
    AcWing 2816. 判断子序列
    AcWing 790. 数的三次方根
    AcWing 802. 区间和
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/1752272.html
Copyright © 2011-2022 走看看