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

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的。