乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      圖片、文件防盜鏈程序 - 為了夢想…… - 博客園

       xnet 2007-01-17
      關(guān)于圖片盜鏈這個(gè)問題,畢竟是自己的勞動成功,很多人不希望別人就那么輕易地偷走了。 這個(gè)功能在很多的論壇上都具有,可能是因?yàn)楸I鏈的行為太多了吧
               反盜鏈的程序其實(shí)很簡單,熟悉ASP.NET 應(yīng)用程序生命周期的話很容易就可以寫一個(gè),運(yùn)用HttpModule在BeginRequest事件中攔截請求就ok了,剩下的工作就是過濾,再過濾!
               如果不熟悉HttpModule的話,可以去MSDN上查閱,介紹非常詳細(xì),地址:ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_aspnetcon/html/f1d2910f-61d0-4541-8af8-c3c108ca351f.htm。這里就不廢話了

       1private void Application_BeginRequest(Object source, EventArgs e)
       2{
       3    HttpApplication application = (HttpApplication)source;
       4    HttpContext context = application.Context;
       5    bool isSafe = true;    //是否合法鏈接
       6    string uri = context.Request.Url.AbsolutePath.ToLower();
       7    if (uri.LastIndexOf("."> 0 && context.Request.UrlReferrer != null)
       8    {
       9        string exp = uri.Substring(uri.LastIndexOf("."));
      10        //這里是判斷文件后綴名是否在排除的文件類型列表之內(nèi)
      11        bool isHas = ClassLibrary.RData.RString.StrIsIncUseSC(exp, config.ImgSafeType.Split(|));
      12        if (isHas)
      13        {
      14            string domainOutter = context.Request.UrlReferrer.Authority.ToLower();    //包含域名和端口
      15            ArrayList arry = Common.Cache.GetDomainValid();//取系統(tǒng)定義的合法的域名綁定列表
      16            isSafe = arry.Contains(domainOutter);    //判斷當(dāng)前請求的域名是否在合法列表之內(nèi)
      17        }

      18    }

      19    //下面就是不合法的時(shí)候的輸出了,如果有默認(rèn)替代圖片則輸出,如果沒有就生成一個(gè),格式為.gif
      20    if (!isSafe)
      21    {
      22        Bitmap img = null;
      23        Graphics g = null;
      24        MemoryStream ms = null;
      25
      26        try
      27        {
      28            string picPath = ClassLibrary.RPath.GetFullDirectory("images/unlawful.gif");
      29            if (File.Exists(picPath))
      30            {
      31                img = new Bitmap(picPath, false);
      32            }

      33            else
      34            {
      35                img = new Bitmap(6464);
      36                g = Graphics.FromImage(img);
      37                g.Clear(Color.White);
      38                Font f = new Font("宋體,黑體,Arial"9,FontStyle.Bold);
      39                SolidBrush s = new SolidBrush(Color.Red);
      40                g.DrawString(Resources.Message.LawlessLink, f, s, 120);
      41                img.Save(picPath, ImageFormat.Gif);
      42            }

      43            ms = new MemoryStream();
      44            img.Save(ms, ImageFormat.Gif);
      45            context.Response.ClearContent();
      46            context.Response.ContentType = "image/Gif";
      47            context.Response.BinaryWrite(ms.ToArray());
      48            context.Response.End();
      49        }

      50        catch
      51        { }
      52        finally
      53        {
      54            if(g != null )
      55                g.Dispose();
      56            img.Dispose();
      57        }

      58    }

      59}

                凡是有利必有害,這樣做最大的缺點(diǎn)就是增加了系統(tǒng)開銷,客戶端的每一請求都要過濾一遍,性能自然要打折扣了。不知道哪位朋友有更好的辦法,或者優(yōu)化的方法,一起來探討探討。

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多