Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitemap page links are broken when application is hosted as sub application #222

Merged
merged 1 commit into from
Aug 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public XmlSiteMapResult(
IEnumerable<string> siteMapCacheKeys,
string baseUrl,
string siteMapUrlTemplate,
ISiteMapLoader siteMapLoader)
ISiteMapLoader siteMapLoader,
IUrlPath urlPath)
{
if (siteMapLoader == null)
throw new ArgumentNullException("siteMapLoader");
Expand All @@ -33,10 +34,13 @@ public XmlSiteMapResult(
this.SiteMapCacheKeys = siteMapCacheKeys;
this.BaseUrl = baseUrl;
this.SiteMapUrlTemplate = siteMapUrlTemplate;
this.siteMapLoader = siteMapLoader;
this.siteMapLoader = siteMapLoader;
this.urlPath = urlPath;
}

private readonly ISiteMapLoader siteMapLoader;
private readonly ISiteMapLoader siteMapLoader;

private readonly IUrlPath urlPath;

/// <summary>
/// Maximal number of links per sitemap file.
Expand Down Expand Up @@ -106,7 +110,7 @@ protected virtual void ExecuteSitemapIndexResult(ControllerContext context, IEnu

// Generate sitemap sitemapindex
var sitemapIndex = new XElement(Ns + "sitemapindex");
sitemapIndex.Add(GenerateSiteMapIndexElements(Convert.ToInt32(numPages), BaseUrl, SiteMapUrlTemplate).ToArray());
sitemapIndex.Add(GenerateSiteMapIndexElements(Convert.ToInt32(numPages), SiteMapUrlTemplate).ToArray());

// Generate sitemap
var xmlSiteMap = new XDocument(
Expand Down Expand Up @@ -204,22 +208,21 @@ public override void ExecuteResult(ControllerContext context)
// Sitemap file for all links
ExecuteSitemapResult(context, flattenedHierarchy, flattenedHierarchyCount, 1);
}
}

/// <summary>
/// Generates the sitemap index elements.
/// </summary>
/// <param name="numPages">The number of pages.</param>
/// <param name="url">The URL.</param>
/// <param name="siteMapUrlTemplate">The site map URL template.</param>
/// <returns>The sitemap index elements.</returns>
protected virtual IEnumerable<XElement> GenerateSiteMapIndexElements(int numPages, string url, string siteMapUrlTemplate)
}

/// <summary>
/// Generates the sitemap index elements.
/// </summary>
/// <param name="numPages">The number of pages.</param>
/// <param name="siteMapUrlTemplate">The site map URL template.</param>
/// <returns>The sitemap index elements.</returns>
protected virtual IEnumerable<XElement> GenerateSiteMapIndexElements(int numPages, string siteMapUrlTemplate)
{
// Generate elements
for (int i = 1; i <= numPages; i++)
{
yield return new XElement(Ns + "sitemap",
new XElement(Ns + "loc", url + "/" + siteMapUrlTemplate.Replace("{page}", i.ToString())));
for (int i = 1; i <= numPages; i++)
{
var pageUrl = urlPath.MakeRelativeUrlAbsolute("~/" + siteMapUrlTemplate.Replace("{page}", i.ToString()));
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 @@ -50,8 +51,9 @@ public ActionResult Create(int page)
this.DefaultRootNode,
this.DefaultSiteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader,
this.urlPath);
}

public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys)
Expand All @@ -61,8 +63,9 @@ public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys)
this.DefaultRootNode,
siteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader,
this.urlPath);
}

public ActionResult Create(int page, IEnumerable<string> siteMapCacheKeys)
Expand All @@ -72,8 +75,9 @@ public ActionResult Create(int page, IEnumerable<string> siteMapCacheKeys)
this.DefaultRootNode,
siteMapCacheKeys,
this.DefaultBaseUrl,
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader);
this.DefaultSiteMapUrlTemplate,
this.siteMapLoader,
this.urlPath);
}

public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys, string baseUrl, string siteMapUrlTemplate)
Expand All @@ -83,8 +87,9 @@ public virtual ActionResult Create(IEnumerable<string> siteMapCacheKeys, string
this.DefaultRootNode,
siteMapCacheKeys,
baseUrl,
siteMapUrlTemplate,
this.siteMapLoader);
siteMapUrlTemplate,
this.siteMapLoader,
this.urlPath);
}

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

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

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

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

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

#endregion
Expand Down