日期:2014-05-17  浏览次数:20413 次

通过HttpModule设置fckeditor分目录上传的问题
已知通过如下代码:
C# code
Session["FCKeditor:UserFilesPath"] = "~/cn/UploadFile/";

可以设置fckeditor的上传文件路径

我现在的需求是中英文网站,根目录为英文网站,有一个UploadFile存放英文网站上传的图片,中文网站在英文网站的根目录下:/cn/,相应中文网站下也有一个UploadFile存放中文网站上传的图片。

我想通过自定义HttpModule,来实现通过判断URL自动设置Fckeditor的UserFilesPath,以实现自动区分Fckeditor的上传目录。
代码如下:
C# code

    public class FckUploadConfig : IHttpModule

    {
        private void Application_AcquireRequestState(object sender, EventArgs e)
        {

            HttpApplication application = (HttpApplication)sender;

            HttpContext context = application.Context;

            HttpRequest request = application.Request;

            HttpResponse response = application.Response;

            context.Session["FCKeditor:UserFilesPath"] = null;

            if (request.Path.ToLower().IndexOf("cn/admin") > 0)
            {
                context.Session["FCKeditor:UserFilesPath"] = "~/cn/UploadFile/";
            }
        }

        public void Dispose()

        { }

        public void Init(HttpApplication application)
        {
            application.AcquireRequestState +=new EventHandler(Application_AcquireRequestState);
        }
    }



通过上述代码,在单独打开IE的情况下,单独上传中文或英文的文件,文件是分目录存放的,但问题是,如果在同一个IE中先打开英文网站上传---正确,修改URL到中文上传---正常,再修改URL返回英文则不正常。应该是SESSION设置的问题,但绕了半天也绕不出去了。

------解决方案--------------------
if (request.Path.ToLower().IndexOf("cn/admin") > 0)
{
context.Session["FCKeditor:UserFilesPath"] = "~/cn/UploadFile/";
}
else
{
context.Session["FCKeditor:UserFilesPath"] = "~/UploadFile/";
}
少了个else逻辑,session不会被修改会英文目录