本帖最后由 eakey 于 2013-06-04 20:22:00 编辑

解决方案 »

  1.   

     public class ResponseImg : IHttpHandler
        {
            static readonly DateTime Refresh;
            static readonly DateTime Now;
            static ResponseImg()
            {
                Now = DateTime.Now;
                Refresh = Now.AddMonths(1);
            }        public void ProcessRequest(HttpContext context)
            {            if (!string.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"]))
                {
                    DateTime IfModifiedSince = DateTime.Parse(context.Request.Headers["If-Modified-Since"]);
                    if (IfModifiedSince > Now)
                    {
                        context.Response.StatusCode = 304;
                        return;
                    }
                }
                
                //string folder = context.Request.QueryString["Folder"];
                string filepath = context.Request.QueryString["FilePath"];
                int width = int.Parse(context.Request.QueryString["Width"]);
                int height = int.Parse(context.Request.QueryString["Height"]);
                string hex = context.Request.QueryString["Hex"];            string path = context.Server.MapPath(string.Format("/Img/{0}", filepath));            byte[] bytes = ImageHelper.Reset(path, width, height);
                //System.Drawing.Image img = ImageHelper.Reset(bytes, width, height);            context.Response.Headers["Last-Modified"] = Refresh.ToString();
                //context.Response.Cache.SetExpires(DateTime.Now.Add(Refresh));
                //context.Response.Cache.SetMaxAge(refresh);
                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.CacheControl = HttpCacheability.Public.ToString();
                context.Response.Cache.SetValidUntilExpires(true);
                //context.Response.StatusCode = 304;
                //img.Save(context.Response.OutputStream, ImageHelper.GetImageFormat(path));
                context.Response.ContentType = "image/" + hex;
                
                context.Response.BinaryWrite(bytes);        }        public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    我用UrlRewrite 然后压缩图片 这样就是生成40*40  360*360像素的图片......
    当然,你可以解密后,再获取正确的地址 再输出
      

  2.   

    真心不明白楼主所说的真实地址是什么,是指图片的URL,还是指图片在服务器上存放的位置,前者你再怎么编码都是没有意义的,总不至于不让浏览器明白吧,而后者也不复杂,就看图片在服务器上怎么存了,如果存在数据库里,带个ID出来,如果直接存在硬盘上,自己弄一套简单的规则稍做加密就可以了。
      

  3.   

    从数据库中取图片:
    Using ASHX files to retrieve DB images
    http://www.developerfusion.com/code/5223/using-ashx-files-to-retrieve-db-images/
      

  4.   

    img src的时候加密。  访问图片页面的时候 解密。  然后输出图片.