图片防盗链
void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.RawUrl.Contains("images/"))
{
if (Request.UrlReferrer == null || !IsSameDomain(Request.UrlReferrer, Request.Url))
{
////
Response.ContentType = "image/jpeg";
string path = Request.MapPath("~/daolian.jpg");
Response.WriteFile(path);
//结束请求
Response.End();
}
}
}
//判断两个域名是否相等
bool IsSameDomain(Uri u1,Uri u2)
{
return Uri.Compare(u1, u2, UriComponents.HostAndPort, UriFormat.SafeUnescaped, StringComparison.CurrentCultureIgnoreCase) == 0 ? true : false;
}