/// <summary> /// Initializes a new instance of the HttpRedirectRuleMatch class. /// </summary> /// <param name="rule">The rule that matched.</param> /// <param name="matchResult">The result of the match.</param> public HttpRedirectRuleMatch(HttpRedirectRuleElement rule, Match matchResult) { if (rule == null) { throw new ArgumentNullException("rule", "rule cannot be null."); } if (matchResult == null) { throw new ArgumentNullException("matchResult", "matchResult cannot be null."); } this.Rule = rule; this.MatchResult = matchResult; }
public void HttpRedirectMatchRules() { HttpRedirectRuleElement[] rules = new HttpRedirectRuleElement[] { new HttpRedirectRuleElement() { Pattern = @"^(https?://)www\.(.*)", RedirectsTo = "$1$2" }, new HttpRedirectRuleElement() { Pattern = @"^(.*)?default\.aspx(.*)", RedirectsTo = "$1index.html$2" } }; HttpRedirectRuleMatcher matcher = new HttpRedirectRuleMatcher(); Uri uri = new Uri("https://www.virtualkeychain.com/vault.html"); Assert.AreEqual("https://virtualkeychain.com/vault.html", matcher.Match(uri, rules).RedirectResult); uri = new Uri("https://virtualkeychain.com/default.aspx?name=home"); Assert.AreEqual("https://virtualkeychain.com/index.html?name=home", matcher.Match(uri, rules).RedirectResult); uri = new Uri("http://localhost/vkc/default.aspx?name=home"); Assert.AreEqual("http://localhost/vkc/index.html?name=home", matcher.Match(uri, rules).RedirectResult); }