zoukankan      html  css  js  c++  java
  • 图片防盗链

    新建一个类库AvoidImage 继承IHttpHandler,记得引用System.Web

    class AvoidImage : IHttpHandler
        {

            #region IHttpHandler 成员

            public bool IsReusable
            {
                //get { throw new NotImplementedException(); }
                get {
                    return true;
                }
            }

            #endregion
            public void ProcessRequest(HttpContext context)
            {
                Uri urlreferrer = context.Request.UrlReferrer;//访问来源地址
                string ip = context.Request.UserHostAddress;//访问来源Ip地址
                string serverhost = context.Request.Url.Host;//当前访问主机地址
                string localIp = ConfigurationManager.AppSettings["LocalIP"];
                if (urlreferrer == null || urlreferrer.Host.ToLower() != serverhost.ToLower() || ip != localIp)
                {
                    context.Response.WriteFile("~/images/index_adr11.gif");
                }
                else
                {
                    context.Response.WriteFile(context.Request.PhysicalPath);
                }
            }
        }


    default.aspx

    <body>
        <form id="form1" runat="server">
        <div>
        <img src="images/Advertise_1.jpg" />
        </div>
        </form>
    </body>

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mane_yao/archive/2010/09/06/5865675.aspx

  • 相关阅读:
    烦人的警告 Deprecated: convertStrings was not specified when starting the JVM
    Python 推送RabbitMQ
    JavaScript-json数组排序
    CSS-返回顶部代码
    CSS-页面滑屏滚动原理
    CSS-图像映射
    CSS-下拉导航条
    CSS-background-position百分比
    CSS- 横向和纵向时间轴
    JavaScript-闭包深入浅出
  • 原文地址:https://www.cnblogs.com/mane/p/1829930.html
Copyright © 2011-2022 走看看