AS.NET-ベース12、Request

5237 ワード


1、パス識別子。
  • http標準は:
  • 「/」はウェブサイトのルートディレクトリを表します。
  • 「./」は上位ディレクトリを表します。
  • 「/」は現在のディレクトリを表します。
  • Asp.net専用ですので、を使います。
  • 「~」は現在のアプリケーションルートディレクトリを表します。
  • <asp:HyperLink runat="server" NavigateUrl="~/a/b.aspx"></asp:HyperLink>
  • 「~」をhtmlに変換して使用できるルートパスに対してルートパスに変換した後、Htmlを認識します。
    Response.Write("<a href='"+VirtualPathUtility.ToAbsolute("~/a/b.aspx"));
  • 2、Virtual PathUtility類のいくつかの主要な方法:
  • string Apple Trailing Slash
  • は、経路が「/」の終端であるかどうかを確認し、そうでない場合は加えます。
  • string Cobine(string basePath、string relativePath)
  • 「~/a/b」+「c.aspx」=「~/a/c.aspx」
  • 「~/a/b/」+「c.aspx」=「~/a/b/c.aspx」
  • string GetDirectory
  • は、仮想パスのディレクトリ部分を返します。
  • string MakeRelative(string from Path、string toPath)
  • は、2つの経路の相対パスを計算する。
  • string ToAbsolute
  • は絶対パス
  • に変換される。
    3、RequestはPage類の属性ですので、asxではcontext.Requestを使います。
  • Request.AppRelativeCurrenent ExectionFilePath
  • は、アプリケーションルートディレクトリに対する現在の実行要求の仮想ディレクトリを取得する。たとえば、「~/ハードラン.アスクス」
  • Request.PhysicalApple Path
  • は、現在のアプリケーションの物理的経路を取得する。「D:\a\a」
  • Request.PhysicalPath
  • は、現在の要求の物理的経路を取得する。「D:a\a\b.aspx」
  • Request.RawUrl
  • は、元のリクエストUrl
  • を取得する。
  • Request.Url
  • 取得要求Url
  • は、Url書き換えに設計された問題と区別されている
  • Request.UrlReferrer
  • ウェブページのソースは、Http新聞のReferrerを読みに行きます。これを通じて盗難防止チェーンを作ります。全域で
  • です。
  • は防犯チェーンとして使われています。一般的に写真に使われています。雷がすべてのページの正確なRequest.UrlReferrerを倉庫に保存していますので、ダウンロード時にReferrerを偽造します。
  • context.Response.ContentType = "image/JPEG";
            string fullpath = HttpContext.Current.Server.MapPath("IMG_5433.JPG");
            using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fullpath))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
                {
                    using (System.Drawing.Font font = new System.Drawing.Font("  ", 30))
                    {
                        if (context.Request.UrlReferrer == null)
                        {
                            g.Clear(System.Drawing.Color.White);
                            g.DrawString("  ", font, System.Drawing.Brushes.Red, 0, 0);
                        }
                        else if(context.Request.UrlReferrer.Host!="localhost")
                        {
                            g.DrawString("        ", font, System.Drawing.Brushes.Red, 0, 0);
                        }                    
                        bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);                    
                    }
                }
            }
  •  
  • Request.UserHostAddress
  • は、訪問者のIPアドレスを取得し、ソースアドレスライブラリに合わせてソースを分析する。
  • Request.UserLanguges
  • 訪問者がサポートする言語は、新聞から得られます。
  • Request.Cookies
  • context.Request.Cookies[mysision ID]
  • Response.co okies["]
  • Request.MapPath
  • は仮想パスをディスク上の物理パスに変換して、プログラムを使う時にやっと確実です。