通过HttpModule实现Fckeditor的分目录上传
2012-01-14 22:20
357 查看
标题不知该怎么写更能表达意思,近期遇到一个中英文版的网站项目,中文和英文的后台都是用的一个Fckeditor,很自然的想到中文和英文通过编辑器上传的文件应该分开存放到各自语言版本的目录中,如各自目录下的UploadFile文件夹,通过网上查资料得知,可以通过设置Session["FCKeditor:UserFilesPath"]来动态改变Fckeditor的上传路径,但这样会带来一个比较烦索的事情就是中文文件的admin下(假定网站根目录为英文,中文位于根目录的/cn/下,每个语言版本的管理后台位于各自的Admin目录下)的文件中,凡是用到Fckeditor的地方都要设置一遍Session["FCKeditor:UserFilesPath"],由此想到是否可以通过HttpModule来实现根据网站目录自动设置Session["FCKeditor:UserFilesPath"],经过测试,整理代码如下:
需要在Web.Config中设置一下:
这样,就可以实现按目录自动设置Session["FCKeditor:UserFilesPath"]了。
using System; using System.Data; using System.Configuration; using System.Web.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace FckConfig { /// <summary> /// FckUploadConfig 的摘要说明 /// </summary> 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; if (request.Path.ToLower().IndexOf("/cn/admin") == 0) { context.Session["FCKeditor:UserFilesPath"] = "~/cn/UploadFile/"; } if (request.Path.ToLower().IndexOf("/admin") == 0) { context.Session["FCKeditor:UserFilesPath"] = "~/UploadFile/"; } } public void Dispose() { } public void Init(HttpApplication application) { application.AcquireRequestState +=new EventHandler(Application_AcquireRequestState); } } }
需要在Web.Config中设置一下:
<httpModules> <add name="test" type="FckConfig.FckUploadConfig"/> </httpModules>
这样,就可以实现按目录自动设置Session["FCKeditor:UserFilesPath"]了。
相关文章推荐
- AS3 下通过HTTP协议 实现Form方式实现二进制文件上传
- 通过html5 File、XMLHttpRequest实现文件上传
- 通过实现IHttpModule初始化Nhibernate的Session
- 在 Android 上通过模拟 HTTP multipart/form-data 请求协议信息实现图片上传
- 在 Android 上通过模拟 HTTP multipart/form-data 请求协议信息实现图片上传
- Nginx可以通过HTTPLimitZoneModule和HTTPCoreModule两个目录来限速
- 通过HttpModule实现数据库防注入
- 通过HttpModule实现数据库防注入
- iOS通过http post 文件流上传文件(头像)代码实现
- Android 开发工具类 32_通过 HTTP 协议实现文件上传
- FCKeditor.NET 自定义上传目录和文件名 [本人亲自测试通过]
- 通过HttpModule实现数据库防注入
- Android学习笔记---28_网络通信之通过HTTP协议实现文件上传,组拼http 的post方法,传输内容
- 通过Node实现http上传文件进度条
- 通过HttpModule实现IP地址屏蔽功能 (转)
- PB通过VDN实现Http上传、下载
- 在Android上通过模拟HTTP multipart/form-data请求协议信息实现图片上传
- 通过HttpModule实现数据库防注入
- 通过HttpModule实现IP地址屏蔽功能
- Nginx Http认证 实现访问网站或目录密码认证保护 | 使用 HttpAuthBasicModule 模块