本文整理汇总了C#中UrlBuilder.BuildUrlMap方法的典型用法代码示例。如果您正苦于以下问题:C# UrlBuilder.BuildUrlMap方法的具体用法?C# UrlBuilder.BuildUrlMap怎么用?C# UrlBuilder.BuildUrlMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlBuilder
的用法示例。
在下文中一共展示了UrlBuilder.BuildUrlMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateConfig
public static UrlRuleConfiguration GenerateConfig(int portalId)
{
//string cacheKey = "UrlRuleConfig" + portalId;
var config = new UrlRuleConfiguration();
config.Rules = new List<UrlRule>();
try
{
// 1 cache by portal
//DnnLog.Trace("Get cache " + portalId );
//config = (UrlRuleConfiguration)DataCache.GetCache(cacheKey);
//if ((config == null))
{
Stopwatch timer = new Stopwatch();
timer.Start();
Logger.Info("Rebuild cache start " + portalId);
//config = new UrlRuleConfiguration { Rules = new List<UrlRule>() };
// generate admin page
GenerateAdminTab(portalId);
//if (false)
{
var builder = new UrlBuilder();
var Rules = builder.BuildUrlMap(portalId);
config.Rules.AddRange(Rules);
var storedRules = UrlRuleController.GetUrlRules(portalId);
foreach (UrlRuleInfo storedRule in storedRules)
{
if (storedRule.CultureCode == "") storedRule.CultureCode = null;
if (storedRule.RedirectDestination == "") storedRule.RedirectDestination = null;
if (storedRule.RedirectDestination != null) storedRule.RedirectDestination = storedRule.RedirectDestination.Trim();
if (storedRule.Url != null) storedRule.Url = storedRule.Url.Trim();
}
// add custom rules to cache
foreach (UrlRuleInfo storedRule in storedRules.Where(r => r.RuleType == (int)UrlRuleType.Custom /* && r.RuleAction == (int)UrlRuleAction.Redirect */)) // custom rule
{
UrlRule rule = new UrlRule()
{
RuleType = (UrlRuleType)storedRule.RuleType,
CultureCode = storedRule.CultureCode,
TabId = storedRule.TabId,
Parameters = storedRule.Parameters,
Action = (UrlRuleAction)storedRule.RuleAction,
RemoveTab = storedRule.RemoveTab,
RedirectDestination = storedRule.RedirectDestination,
RedirectStatus = storedRule.RedirectStatus,
Url = storedRule.Url
};
config.Rules.Add(rule);
}
// add rule for sitemap.xml rewrite to sitemap.aspx
/* replaced by a handler
UrlRule sitemapRule = new UrlRule()
{
RuleType = UrlRuleType.Custom,
Action = UrlRuleAction.Rewrite,
RedirectDestination = "~/Sitemap.aspx",
Url = ".*sitemap.xml"
};
config.Rules.Add(sitemapRule);
*/
foreach (UrlRule rule in config.Rules)
{
if (rule.CultureCode == "") rule.CultureCode = null;
if (rule.RedirectDestination == "") rule.RedirectDestination = null;
rule.Url = rule.Url.ToLower();
// set RedirectDestination for automatic redirections corresponding to rewrite rule
if (rule.RuleType == UrlRuleType.Module && rule.Action == UrlRuleAction.Rewrite && string.IsNullOrEmpty(rule.RedirectDestination))
{
rule.RedirectDestination = rule.Parameters.Replace('=', '/').Replace('&', '/');
}
else if (rule.RuleType == UrlRuleType.Module && rule.Action == UrlRuleAction.Redirect && string.IsNullOrEmpty(rule.RedirectDestination))
{
var rewriteRule = config.Rules.FirstOrDefault(r => r.RuleType == UrlRuleType.Module && r.Parameters == rule.Parameters && r.Action == UrlRuleAction.Rewrite);
if (rewriteRule != null)
{
rule.RedirectDestination = rewriteRule.Url;
}
}
if (rule.RedirectDestination != null)
{
rule.RedirectDestination = rule.RedirectDestination.ToLower();
}
}
var OldRules = new List<UrlRuleInfo>(storedRules);
var DistuctRules = config.Rules.Where(r => r.RuleType != UrlRuleType.Custom)
.GroupBy(r => new { r.RuleType, r.CultureCode, r.TabId, r.Url })
.Select(g => g.First());
foreach (UrlRule rule in DistuctRules)
{
//.........这里部分代码省略.........