我这个是webservice的,放到IIS上,是这样的 例如:用户A在浏览器输入192.168.1.199/image/i.jpg 不能让他出现i.jpg的图片
必须是用我们这个软件后才能得到图片,单纯输入ip地址获取图片 不可以,当单纯输入IP地址/image这样的就直接给跳转到其他页面

解决方案 »

  1.   

    做一个专门的ImageDownload的Handler或者aspx页面,通过IO存取。
    并且直接把所有的 */image/* 重定向到你需要的错误页或者提示页。
      

  2.   

    rewrite,httphandler,图片流输出
    思路都是吧,这个后缀或者路径的,访问之前增加逻辑判断
      

  3.   

    Image img = Image.FromFile(imagefullpath);            string contenttype = "image/jpeg";            if (img.RawFormat == ImageFormat.Jpeg)
                {
                    contenttype = "image/jpeg";
                }
                else if(img.RawFormat==ImageFormat.Gif)
                {
                    contenttype = "image/gif";
                }
                else if (img.RawFormat == ImageFormat.Bmp)
                {
                    contenttype = "image/bmp";
                }
                else if (img.RawFormat == ImageFormat.Png)
                {
                    contenttype = "image/png";
                }
                else if (img.RawFormat == ImageFormat.Tiff)
                {
                    contenttype = "image/tiff";
                }
                MemoryStream ms = new MemoryStream();            int maxWidth = 100;
                int maxHeight = 100;            if (string.IsNullOrEmpty(Request.QueryString["height"]) == false && int.TryParse(Request.QueryString["height"], out maxHeight) == false)
                {
                    maxHeight = 100;
                }
                if (string.IsNullOrEmpty(Request.QueryString["width"]) == false && int.TryParse(Request.QueryString["width"], out maxWidth) == false)
                {
                    maxWidth = 100;
                }            Size _newSize = ResizeImage(img.Width, img.Height, maxWidth, maxHeight);            if (_newSize.Width < maxWidth && _newSize.Height < maxHeight)
                {
                    try
                    {
                        img.Save(ms, img.RawFormat);
                        Response.ClearContent();
                        Response.ContentType = contenttype;
                        Response.BinaryWrite(ms.ToArray());
                        Response.End();
                        return View();
                    }
                    finally
                    {
                        img.Dispose();
                    }
                }            Graphics g = null;
                Bitmap b = null;
                try
                {
                    b = new Bitmap(_newSize.Width, _newSize.Height);
                    g = Graphics.FromImage(b);
                    g.InterpolationMode = InterpolationMode.High;
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    //清除整个绘图面并以透明背景色填充
                    g.Clear(Color.White);                g.DrawImage(img, new Rectangle(0, 0, _newSize.Width, _newSize.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
                    EncoderParameters parameters = new EncoderParameters(1);
                    parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ((long)95L));
                    b.Save(ms, img.RawFormat);                Response.ClearContent();
                    Response.ContentType = contenttype;
                    Response.BinaryWrite(ms.ToArray());
                    Response.End();
                    return View();
                }
                finally
                {
                    b.Dispose();
                    g.Dispose();
                    img.Dispose();
                }
      

  4.   

    这个是我MVC项目里的一段代码,供你参考。
      

  5.   

    转数据流了,参考把图片转数据流存到数据库的做法,只是你把图片转成另一种文件。这样下下来也没多大作用
    图片转数据流存到数据库
                        string fileName = openFileDialog1.FileName;
                        FileInfo fi = new FileInfo(fileName);                    FileStream fs = fi.OpenRead();
                        byte[] bytes = new byte[fs.Length];
                        fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
                       数据库字段varbinary(MAX)= bytes;读出来转文件(基本上什么格式都可以)
                FileStream fs = new FileStream(@"d:\11.xls".ToString(), FileMode.CreateNew);
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(((kuan1)bind.Current).picbin2.ToArray(), 0, ((kuan1)bind.Current).picbin2.Length);
                bw.Close();
                fs.Close();            string strFileName = @"d:\11.xls";
                Object refmissing = System.Reflection.Missing.Value;如果是图片文件直接显示
                    MemoryStream ms = new MemoryStream(数据库字段.ToArray());
                    pictureBox1.Image = Image.FromStream(ms);//
      

  6.   

    我只知道java中可以用顾虑器的 ,判断session中有没有 需要的值,然后进行跳转或者下载
      

  7.   

    是这样的,是用户必须进我们这个软件才能看到 软件里的图,不能直接输入比如192.168.1.188/image/s.jpg这样获取图片,就是为了防止他输入/image/s.jpg这样 不知道如何防止
      

  8.   


    http://www.cnblogs.com/ghfsusan/archive/2011/02/25/1964579.html
      

  9.   

     直接访问图面 asp.net 无法控制啊。 除非图片扩展名映射给asp.net 处理。
    建议使用 ISAPI_Rewrite# 防盗链
    # RewriteCond Host: (.+)
    # RewriteCond Referer: (?!http://\1.*).*
    # RewriteCond Referer: (?!http://(.*)(www\.你的URL\.com|\.你的URL\.com|\.baidu\.com|\.google\.com|\.google\.cn|\.g\.cn|\.gougou\.com|\.soso\.com|\.sogou\.com|\.youdao\.com|\.bing\.com|\.yahoo\.com|\.yahoo\.cn)).+
    # RewriteRule .*\.(?:gif|jpg|png|jpeg|bmp|) /block.gif [I,O,N]