Global.asax或IHttpModule实现屏蔽ip和图片防盗链
生活随笔
收集整理的這篇文章主要介紹了
Global.asax或IHttpModule实现屏蔽ip和图片防盗链
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Global.asax實現屏蔽ip和圖片防盜鏈 protected void Application_BeginRequest(object sender, EventArgs e)
{
//屏蔽ip
//if (HttpContext.Current.Request.UserHostAddress == "127.0.0.1")
//{
// HttpContext.Current.Response.Write("你已被屏蔽");
// HttpContext.Current.Response.End();
//}
//圖片防盜鏈,只要是圖片請求,并且請求地址不是本服務器都將圖片換位下面的盜鏈圖片
if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".jpg") && HttpContext.Current.Request.UrlReferrer.Host != "localhost:2535")
{
HttpContext.Current.Response.WriteFile(HttpContext.Current.Server.MapPath("~/imgs/%D7%EE%D6%D5%BB%C3%CF%EB%A2%F7-%CA%A5%CD%AF%BD%B5%C1%D920080427084745.jpg"));
}
}
{
//屏蔽ip
//if (HttpContext.Current.Request.UserHostAddress == "127.0.0.1")
//{
// HttpContext.Current.Response.Write("你已被屏蔽");
// HttpContext.Current.Response.End();
//}
//圖片防盜鏈,只要是圖片請求,并且請求地址不是本服務器都將圖片換位下面的盜鏈圖片
if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".jpg") && HttpContext.Current.Request.UrlReferrer.Host != "localhost:2535")
{
HttpContext.Current.Response.WriteFile(HttpContext.Current.Server.MapPath("~/imgs/%D7%EE%D6%D5%BB%C3%CF%EB%A2%F7-%CA%A5%CD%AF%BD%B5%C1%D920080427084745.jpg"));
}
}
總結
以上是生活随笔為你收集整理的Global.asax或IHttpModule实现屏蔽ip和图片防盗链的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第九章 子查询
- 下一篇: 运维监控之Nagios实战(五)Nagi