Asp.Net画像ファイル盗難防止チェーン(労働成果尊重)及びBeginRequest事件学習

3234 ワード

写真のチェーンを盗むことについて、結局自分の労働が成功したので、多くの人は他の人がそんなに簡単に盗むことを望んでいません.この機能は多くのフォーラムに搭載されていますが、チェーンを盗む行為が多すぎるからかもしれません.
反盗鎖のプログラムは実はとても簡単で、ASPに熟知しています.NETアプリライフサイクルなら簡単に書くことができますが、HttpModuleを使ってBeginRequestイベントでリクエストをブロックすればOKです.残りの仕事はフィルタリング、フィルタリングです.
HttpModuleに詳しくない場合は、MSDNで調べることができます.詳しくは、住所:ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_aspnetcon/html/f1d2910f-61d0-4541-8af8-c3c108ca351f.htm.ここはくだらないことは言わない
 
  
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();
}
}
}

すべて有利で必ず有害で、このようにする最大の欠点はシステムのオーバーヘッドを増加して、クライアントのすべての要求はすべて1回濾過して、性能は自然に割引して差し引きます.どの友達がもっと良い方法があるか、あるいは最適化の方法があるか分からないので、一緒に検討してみましょう.
ファイルの盗難チェーン機能の再接続を実現する:
まずグローバルファイルGlobalを追加します.asax
アプリケーション_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();
}
}