随笔-8  评论-30  文章-0  trackbacks-0
By:tzz

此设置方法通用于Image,Flash和Link类的浏览目录。这里所说的浏览上传目录指的是在点击Flash或者Image或者Link按钮时,选择“浏览服务器”时的初始目录,下文称之为用户文件目录。我们现在要实现的,就是将用户文件目录根据用户的不同而改变。比如我根据用户ID来建立文件夹来为用户提供上传服务。则ID=1的用户,其用户文件目录就是...../1/,而ID=2的用户,其用户文件目录就是...../2/。有点啰嗦,。下文我就根据用户ID来设置用户文件目录。

首先我们来分析FckEditor是如何来确定用户文件目录的。我们来看看FckEditor设置用户文件目录的代码。
protected string UserFilesPath
{
    
get
    
{
        
if ( sUserFilesPath == null )
        
{
            
// Try to get from the "Application".
            sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"] ;

            
// Try to get from the "Session".
            if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
            
{
                sUserFilesPath 
= (string)Session["FCKeditor:UserFilesPath"] ;
                
                
// Try to get from the Web.config file.
                if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
                
{
                    sUserFilesPath 
= System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"] ;
                    
                    
// Otherwise use the default value.
                    if ( sUserFilesPath == null || sUserFilesPath.Length == 0 ) 
                        sUserFilesPath 
= DEFAULT_USER_FILES_PATH ;

                    
// Try to get from the URL.
                    if ( sUserFilesPath == null || sUserFilesPath.Length == 0 ) 
                    
{
                        sUserFilesPath 
= Request.QueryString["ServerPath"] ;
                    }

                }

            }


            
// Check that the user path ends with slash ("/")
            if ( ! sUserFilesPath.EndsWith("/") )
                sUserFilesPath 
+= "/" ;

            
// add by tzz for multiuser
            
//sUserFilesPath = sUserFilesPath + Session["user_id"].ToString() + "/" ;
        }

        
return sUserFilesPath ;
    }

}

可以看到,FckEditor是从“UserFilesPath”来获取用户文件目录的。我们可以看到FckEditor取UserFilesPath的顺序为:Application["FCKeditor:UserFilesPath"] -->Session["FCKeditor:UserFilesPath"]--->System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"]-->默认值。Application、web.config都是全局的,我们不用,所以我们的目标就是通过设置Session["FCKeditor:UserFilesPath"]来根据不同的用户设置不同的用户文件目录。可能会有朋友问,为什么不直接引用Solution中的Session,比如自己的webapplication中的Session[UserID],然后直接在上述代码里修改,比如加入:
sUserFilesPath = sUserFilesPath + Session["user_id"].ToString() + "/" ;
这是行不通的。Session不能在两个不同的应用程序之间传递!

接下来的问题就在于在哪里改变Session["FCKeditor:UserFilesPath"]。这里很重要。切忌,要在“~\FCKeditor\editor\filemanager\browser\default\connectors\aspx\connector.aspx”的OnInit事件中设定,而不能在Page_Load事件中设定。上文说过我们不能通过使用启动工程中的Session,那我们如果得到用户的ID呢?对,通过url的参数。为了实现通过url传递有关用户ID的参数,我们就必须在使用FckEditor的页面增加如下代码,设置ImageBrowserURL、LinkBrowserURL、FlashBrowserURL的值:
string sImageBrowserURL = "/demo/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/aspx/connector.aspx&UserID=" + user_id.ToString();
string sFlashBrowserURL = "/demo/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/aspx/connector.aspx&UserID=" + user_id.ToString();
string sLinkBrowserURL = "/demo/FCKeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/aspx/connector.aspx&UserID=" + user_id.ToString();
FCKeditor_diary.ImageBrowserURL 
= sImageBrowserURL;
FCKeditor_diary.LinkBrowserURL 
= sLinkBrowserURL;
FCKeditor_diary.FlashBrowserURL 
= sFlashBrowserURL;
其中,“demo”是你的应用程序。现在我们可以在connector.aspx的OnInit事件中加代码了:
<script runat="server" language="C#">
    
protected override void OnInit(EventArgs e)
    
{
        
if (Request.QueryString["UserID"== null)
        
{
            Session[
"FCKeditor:UserFilesPath"= "~/uploaded/"//设置默认值
        }

        
else
        
{
            Session[
"FCKeditor:UserFilesPath"= "~/uploaded/" + Request.QueryString["UserID"+ "/";
        }

    }

</script>


然后编译,运行。该方法不用修改FckEditor的源文件,感觉还是比较简单的。

posted on 2006-11-18 15:53 阿土仔的世界 阅读(1334) 评论(8)  编辑 收藏 引用 网摘 所属分类: DotNET

评论:
# re: .Net下FCKEditor按照不同用户自动设置不同浏览上传目录的实现 2007-06-22 16:57 | AAA
Session["FCKeditor:UserFilesPath"] 在使用它的页面的OnInit里设置就可以了.所以,就不需要Request传递USERID了.呵 呵.   回复  更多评论
  
# re: .Net下FCKEditor按照不同用户自动设置不同浏览上传目录的实现 2007-07-29 11:51 | 钻石
# re: .Net下FCKEditor按照不同用户自动设置不同浏览上传目录的实现 2007-08-23 12:20 | searover
用request传? 那如果我知道你的id,那我不就可以看到你上传的文件了吗?  回复  更多评论
  
# re: .Net下FCKEditor按照不同用户自动设置不同浏览上传目录的实现 2007-08-23 12:21 | searover
这个安全性还是要判断的了  回复  更多评论
  
# re: .Net下FCKEditor按照不同用户自动设置不同浏览上传目录的实现 2007-12-30 08:36 | dfhdfh
http://sesso-gratis-movie-ragazze.gradis-tun.info
http://tv-sexe-forum.culs-ugx.info
http://donna-fanno-sesso-cavallo-cane.fatte-tun.info
http://salope-sexe-exhibe.succhiano-ugx.info
http://porno-reggicalza-gratis.fatte-tun.info
http://sexe-japonaise-photo.culs-ugx.info
http://fighe-pelose-celebrita-gratis.fatte-tun.info
http://femme-aime-cul.succhiano-ugx.info
http://video-gratis-porno-anale.sculaccia-tun.info
http://veut-cul-com-gratuis.senegalese-ugx.info
http://chiavata-video.gradis-tun.info
http://sexe-clip-gratuit-lesbienne.culs-ugx.info
http://porno-super.gradis-tun.info
http://sexe-lieu.culs-ugx.info
http://negro-gigante.sculaccia-tun.info
http://jeu-adulte-sexe.senegalese-ugx.info
http://fucked-matura-movie.fatte-tun.info
http://travesti-soumise-black.succhiano-ugx.info
http://foto-sexy-monica-bellucci.gradis-tun.info
http://petite-salope-mini-jupe.culs-ugx.info
http://gotiche-hard-sesso-diciottenne.sculaccia-tun.info
http://dvd-baise.senegalese-ugx.info
http://inurl-category-inurl-fetish-intitle-video.sculaccia-tun.info
http://sexe-string-cul-chatte.senegalese-ugx.info
http://moglie-racconto.fatte-tun.info
http://extrait-film-cul.senegalese-ugx.info
http://justine-porno-star.gradis-tun.info
http://grosse-bite-porno-photo.culs-ugx.info
http://rubinetto-fontana-acqua-calda-fredda.gradis-tun.info
http://liste-site-rencontre-sexe.succhiano-ugx.info
http://cazzo-fica-xxx-porno.gradis-tun.info
http://ai-encule.senegalese-ugx.info
http://matura-pompinare-com.gradis-tun.info
http://gay-pisse-cul.succhiano-ugx.info
http://foto-vip-nuda-nudo.fatte-tun.info
http://pute-a-vannes.senegalese-ugx.info
http://sesso-uomo-uomo.fatte-tun.info  回复  更多评论
  
# re: .Net下FCKEditor按照不同用户自动设置不同浏览上传目录的实现 2008-04-23 17:28 | m_ptrReality
支持AAA的说法,直接在使用FCKEditor的页面里面设置
Session["FCKeditor:UserFilesPath"]="XXX"
就可以了  回复  更多评论
  

只有注册用户登录后才能发表评论, 未注册用户请先注册
网站导航: