防止盗链的url重写


+展开
-C#
bool IHttpHandler.IsReusable
    {
        get { return true; }
    }

    void IHttpHandler.ProcessRequest(HttpContext context)
    {
        string FileName = context.Server.MapPath(context.Request.FilePath);
        if (context.Request.UrlReferrer.Host == null)
        {
            context.Response.ContentType = "image/JPEG";
            context.Response.WriteFile("/no.jpg");
        }
        else
        {
            if (context.Request.UrlReferrer.Host.IndexOf("mydomain.com") > 0)
            {
                context.Response.ContentType = "image/JPEG";
                context.Response.WriteFile(FileName);
            }
            else
            {
                context.Response.ContentType = "image/JPEG";
                context.Response.WriteFile("no/jpg");
            }
        }
    }



//web.config里添加一下代码
+展开
-XML
<httpHandlers>
<add verb="*path="*.jpgtype="JpgHandler, MyDll" />
</httpHandlers>

加支付宝好友偷能量挖...


评论(0)网络
阅读(116)喜欢(0)Asp.Net/C#/WCF