复制代码 代码如下:
 
private void Application_BeginRequest(Object source, EventArgs e) 
{ 
HttpApplication application = (HttpApplication)source; 
HttpContext context = application.Context; 
bool isSafe = true; //是否合法链接 
string uri = context.Request.Url.AbsolutePath.ToLower(); 
if (uri.LastIndexOf(“.”) > 0 && context.Request.UrlReferrer != null) 
{ 
string exp = uri.Substring(uri.LastIndexOf(“.”)); 
//这里是判断文件后缀名是否在排除的文件类型列表之内 
bool isHas = ClassLibrary.RData.RString.StrIsIncUseSC(exp, config.ImgSafeType.Split(‘|')); 
if (isHas) 
{ 
string domainOutter = context.Request.UrlReferrer.Authority.ToLower(); //包含域名和端口 
ArrayList arry = Common.Cache.GetDomainValid();//取系统定义的合法的域名绑定列表 
isSafe = arry.Contains(domainOutter); //判断当前请求的域名是否在合法列表之内 
} 
} 
//下面就是不合法的时候的输出了,如果有默认替代图片则输出,如果没有就生成一个,格式为。gif 
if (!isSafe) 
{ 
Bitmap img = null; 
Graphics g = null; 
MemoryStream ms = null; 
try 
{ 
string picPath = ClassLibrary.RPath.GetFullDirectory(“images/unlawful.gif”); 
if (File.Exists(picPath)) 
{ 
img = new Bitmap(picPath, false); 
} 
else 
{ 
img = new Bitmap(**, **); 
g = Graphics.FromImage(img); 
g.Clear(Color.White); 
Font f = new Font(“宋体,黑体,Arial”, 9,FontStyle.Bold); 
SolidBrush s = new SolidBrush(Color.Red); 
g.DrawString(Resources.Message.LawlessLink, f, s, 1, 20); 
img.Save(picPath, ImageFormat.Gif); 
} 
ms = new MemoryStream(); 
img.Save(ms, ImageFormat.Gif); 
context.Response.ClearContent(); 
context.Response.ContentType = “image/Gif”; 
context.Response.BinaryWrite(ms.ToArray()); 
context.Response.End(); 
} 
catch 
{ } 
finally 
{ 
if(g != null ) 
g.Dispose(); 
img.Dispose(); 
} 
} 
} 
复制代码 代码如下:
 
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(); 
} 
}
新闻热点
疑难解答
图片精选