標籤:
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 內部重新導向