Asp.net 图片文件防盗链介绍

想要实现文件放盗链的功能

首先添加一个全局文件 Global.asax

在 Application_BeginRequest中我们可以判断Http报文头中的UrlReferre是否来源本站。

if (HttpContext.Current.Request.UrlReferrer != null)
{
if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) && HttpContext.Current.Request.UrlReferrer.Host != "localhost")
{
HttpContext.Current.Response.WriteFile(HttpContext.Current.Server.MapPath("~/jzdl.jpg"));
HttpContext.Current.Response.End();
}
}
原文地址:https://www.cnblogs.com/wangsai/p/4113328.html