asp.net 內部重新導向

來源:互聯網
上載者:User

標籤:

1.

        /*         * 2、         * Context.RewritePath()         * 使用給定路徑重寫 URL。(內部重寫)         * 內部請求重寫         */        public static void TestTwo()        {            //帶有參數 處理            //http://localhost:49796/testtwo/{id}            string result = "";            if (Contains(AbsolutePath, @"testtwo/\d+$", out result))            {                RewritePath(GetVirtualPath("~/test/testone.aspx?id=" + GetIntStr(result)));            }            //沒有參數            //http://localhost:49796/testtwo{*catchall}            if (AbsolutePath.Contains("testtwo"))            {                RewritePath(GetVirtualPath("~/test/testone.aspx"));            }        }        /*         * 3、         * Context.RewritePath()         * 使用給定路徑重寫 URL。(內部重寫)         * 內部請求執行轉移         */        public static void TestThree()        {            //帶有參數 處理            //http://localhost:49796/testtwo/{id}/{name}/            string result = "";            if (Contains(AbsolutePath, @"testthree/\d+/\w+/$", out result))            {                result = result.Replace("testthree","");                _Server.Transfer("~/test/testone.aspx?id=" + GetIntStr(result) + "&name=" + GetStringStr(result));            }            //沒有參數            if (AbsolutePath.Contains("testthree"))            {                _Server.Transfer("~/test/testone.aspx");            }        }

正則匹配

        //判斷 制定的字串 在源字串中是否匹配        //返回 第一個匹配項        private static bool Contains(string source, string target, out string firstMatch)        {            firstMatch = "";            Match result = Regex.Match(source, target, RegexOptions.IgnoreCase | RegexOptions.Singleline);            if (result.Success)            {                firstMatch = result.Value;                return true;            }            return false;        }        //擷取字串中的第一個數字字元匹配項        private static string GetIntStr(string source)        {            Match result = Regex.Match(source, @"(\d+)", RegexOptions.IgnoreCase | RegexOptions.Singleline);            if (result.Success)            {                return result.Value;            }            return "";        }        //擷取字串中 第一個字串匹配項        private static string GetStringStr(string source)        {            Match result = Regex.Match(source, @"([a-z_]+)", RegexOptions.IgnoreCase | RegexOptions.Singleline);            if (result.Success)            {                return result.Value;            }            return "";        }

2.兩張圖片對比區別

 

asp.net 內部重新導向

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.