Skip to content

Commit

Permalink
Fixes maartenba#222, sitemap links are broken in sub-application.
Browse files Browse the repository at this point in the history
  • Loading branch information
NightOwl888 committed Sep 20, 2013
1 parent 4732916 commit 9200f90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public XmlSiteMapResult(
IEnumerable<string> siteMapCacheKeys,
string baseUrl,
string siteMapUrlTemplate,
ISiteMapLoader siteMapLoader)
ISiteMapLoader siteMapLoader,
IUrlPath urlPath)
{
if (siteMapLoader == null)
throw new ArgumentNullException("siteMapLoader");
throw new ArgumentNullException("siteMapLoader");
if (urlPath == null)
throw new ArgumentNullException("urlPath");

this.Ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
this.Page = page;
Expand All @@ -34,9 +37,11 @@ public XmlSiteMapResult(
this.BaseUrl = baseUrl;
this.SiteMapUrlTemplate = siteMapUrlTemplate;
this.siteMapLoader = siteMapLoader;
this.urlPath = urlPath;
}

protected readonly ISiteMapLoader siteMapLoader;
protected readonly IUrlPath urlPath;
protected readonly List<string> duplicateUrlCheck = new List<string>();

/// <summary>
Expand Down Expand Up @@ -223,7 +228,8 @@ protected virtual IEnumerable<XElement> GenerateSiteMapIndexElements(int numPage
// Generate elements
for (int i = 1; i <= numPages; i++)
{
var pageUrl = baseUrl + "/" + siteMapUrlTemplate.Replace("{page}", i.ToString());
var combinedPath = urlPath.Combine(urlPath.AppDomainAppVirtualPath, siteMapUrlTemplate.Replace("{page}", i.ToString()));
var pageUrl = baseUrl + urlPath.MakeVirtualPathAppAbsolute(combinedPath);
yield return new XElement(Ns + "sitemap", new XElement(Ns + "loc", pageUrl));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public virtual ActionResult Create()
this.DefaultSiteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public ActionResult Create(int page)
Expand All @@ -51,7 +52,8 @@ public ActionResult Create(int page)
this.DefaultSiteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys)
Expand All @@ -62,7 +64,8 @@ public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys)
siteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public ActionResult Create(int page, IEnumerable<string> siteMapCacheKeys)
Expand All @@ -73,7 +76,8 @@ public ActionResult Create(int page, IEnumerable<string> siteMapCacheKeys)
siteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys, string baseUrl, string siteMapUrlTemplate)
Expand All @@ -84,7 +88,8 @@ public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys, string
siteMapCacheKeys,
baseUrl,
siteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public ActionResult Create(int page, IEnumerable<string> siteMapCacheKeys, string baseUrl, string siteMapUrlTemplate)
Expand All @@ -95,7 +100,8 @@ public ActionResult Create(int page, IEnumerable<string> siteMapCacheKeys, strin
siteMapCacheKeys,
baseUrl,
siteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public virtual ActionResult Create(ISiteMapNode rootNode)
Expand All @@ -106,7 +112,8 @@ public virtual ActionResult Create(ISiteMapNode rootNode)
this.DefaultSiteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public ActionResult Create(int page, ISiteMapNode rootNode)
Expand All @@ -117,7 +124,8 @@ public ActionResult Create(int page, ISiteMapNode rootNode)
this.DefaultSiteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public virtual ActionResult Create(ISiteMapNode rootNode, string baseUrl, string siteMapUrlTemplate)
Expand All @@ -128,7 +136,8 @@ public virtual ActionResult Create(ISiteMapNode rootNode, string baseUrl, string
this.DefaultSiteMapCacheKeys,
baseUrl,
siteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

public ActionResult Create(int page, ISiteMapNode rootNode, string baseUrl, string siteMapUrlTemplate)
Expand All @@ -139,7 +148,8 @@ public ActionResult Create(int page, ISiteMapNode rootNode, string baseUrl, stri
this.DefaultSiteMapCacheKeys,
baseUrl,
siteMapUrlTemplate,
this.siteMapLoader);
this.siteMapLoader,
this.urlPath);
}

#endregion
Expand All @@ -159,13 +169,9 @@ protected virtual string DefaultSiteMapUrlTemplate
get { return "sitemap-{page}.xml"; }
}

protected virtual string DefaultBaseUrl
protected virtual string DefaultBaseUrl
{
get
{
var url = urlPath.MakeRelativeUrlAbsolute("~/");
return url.Remove(url.Length - 1);
}
get { return urlPath.ResolveServerUrl("~/", false); }
}

protected virtual IEnumerable<string> DefaultSiteMapCacheKeys
Expand Down

0 comments on commit 9200f90

Please sign in to comment.