首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

IHttpModule 重定向css中的图片解决方法

2012-12-20 
IHttpModule 重定向css中的图片现在的需求是这样的网站上的images文件夹有很多图片 而且若干个网站中的Ima

IHttpModule 重定向css中的图片
现在的需求是这样的
网站上的images文件夹有很多图片 而且若干个网站中的Images里面的图片都差不多
现在把他们集中在一服务器上

但现在我不想修改css

通过IHttpModule来实习重定向 

void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;
            string url = app.Context.Request.Url.ToString().ToLower();

            if (url.Contains("/images/"))
            {
string newurl="";//直接用浏览器可以浏览
                //app.Context.RewritePath(url);//用原来的路径也不可以 郁闷
app.Context.RewritePath(newurl);//不可以浏览
            }
        }
[最优解释]
IIS中设置映射,参考:
Stopping hot-linking with IIS and ASP.NET
http://mvolo.com/stopping-hotlinking-with-iis-and-aspnet
文章中的
Enabling LeechGuard to protect images on IIS6小结
[其他解释]
你需要在IIS中映射图片文件扩展名到aspnet_isapi, 默认jpg什么的是不进asp.net 的pipeline的。

热点排行