tan
站在牛顿头上吃苹果的程序员

       在WEB开发中,有时候为了自己的成功不被别人所用,有时候会使用到图片放盗链,下载针对实现方法做以说明:

大致步骤

一. 获取用户请求地址

string host = context.Request.UrlReferrer.Host;

二. 清空输出缓存

 Context.Respone.Expires=0;

三.清空输出内容

Context.Respont.Clear();

四. //判断用户请求的host是否为本地

  

            if (host == "localhost")

            {

                //设置响应输出内容的格式

                context.Response.ContentType = "image/jpeg";

                //获得用户原始请求的图片

                context.Response.WriteFile(context.Request.PhysicalPath);

                //结束输出响应

                context.Response.End();

            }

            else

            {

                //设置错误图片的格式

                context.Response.ContentType = "image/gif";

                //向客户端输出错误图片

                context.Response.WriteFile(context .Server .MapPath("error.gif"));

                context.Response.End();

            }

 

posted on 2010-03-07 16:42  tanliang  阅读(689)  评论(0编辑  收藏  举报