private void ProcessRewriteAction(InboundRule inboundRule, Uri uri, Match inboundRuleMatch, Match lastConditionMatch, InboundRuleResult ruleResult) { var redirectAction = inboundRule.Action as Rewrite; var rewriteUrl = redirectAction.RewriteUrl; var rewriteItemAnchor = redirectAction.RewriteItemAnchor; if (string.IsNullOrEmpty(rewriteUrl)) { ruleResult.RuleMatched = false; return; } // process token replacements var replacements = new RewriteHelper.Replacements { RequestHeaders = RequestHeaders, RequestServerVariables = RequestServerVariables }; rewriteUrl = RewriteHelper.ReplaceTokens(replacements, rewriteUrl); if (redirectAction.AppendQueryString) { rewriteUrl += uri.Query; } rewriteUrl = RewriteHelper.ReplaceRuleBackReferences(inboundRuleMatch, rewriteUrl); rewriteUrl = RewriteHelper.ReplaceConditionBackReferences(lastConditionMatch, rewriteUrl); ruleResult.RewrittenUri = new Uri(rewriteUrl); ruleResult.StopProcessing = redirectAction.StopProcessingOfSubsequentRules; }
private void ProcessItemQueryRedirectAction(InboundRule inboundRule, Uri uri, Match inboundRuleMatch, Match lastConditionMatch, InboundRuleResult ruleResult) { var redirectAction = inboundRule.Action as ItemQueryRedirect; var itemQuery = redirectAction.ItemQuery; if (string.IsNullOrEmpty(itemQuery)) { ruleResult.RuleMatched = false; return; } // process token replacements in the item query itemQuery = RewriteHelper.ReplaceRuleBackReferences(inboundRuleMatch, itemQuery); itemQuery = RewriteHelper.ReplaceConditionBackReferences(lastConditionMatch, itemQuery); var rewriteItemId = ExecuteItemQuery(itemQuery); if (!rewriteItemId.HasValue) { ruleResult.RuleMatched = false; return; } string rewriteUrl = GetRewriteUrlFromItemId(rewriteItemId.Value, null, null); // process token replacements var replacements = new RewriteHelper.Replacements { RequestHeaders = RequestHeaders, RequestServerVariables = RequestServerVariables }; rewriteUrl = RewriteHelper.ReplaceTokens(replacements, rewriteUrl); rewriteUrl = RewriteHelper.ReplaceRuleBackReferences(inboundRuleMatch, rewriteUrl); rewriteUrl = RewriteHelper.ReplaceConditionBackReferences(lastConditionMatch, rewriteUrl); ruleResult.RewrittenUri = new Uri(rewriteUrl); ruleResult.StopProcessing = redirectAction.StopProcessingOfSubsequentRules; }