diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResult.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResult.cs index 80f4dc08..e8b1d299 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResult.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResult.cs @@ -22,10 +22,13 @@ public XmlSiteMapResult( IEnumerable 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; @@ -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 duplicateUrlCheck = new List(); /// @@ -223,7 +228,8 @@ protected virtual IEnumerable 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)); } } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResultFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResultFactory.cs index 1c216830..3da004ac 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResultFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/XmlSiteMapResultFactory.cs @@ -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) @@ -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 siteMapCacheKeys) @@ -62,7 +64,8 @@ public virtual ActionResult Create(IEnumerable siteMapCacheKeys) siteMapCacheKeys, this.DefaultBaseUrl, this.DefaultSiteMapUrlTemplate, - this.siteMapLoader); + this.siteMapLoader, + this.urlPath); } public ActionResult Create(int page, IEnumerable siteMapCacheKeys) @@ -73,7 +76,8 @@ public ActionResult Create(int page, IEnumerable siteMapCacheKeys) siteMapCacheKeys, this.DefaultBaseUrl, this.DefaultSiteMapUrlTemplate, - this.siteMapLoader); + this.siteMapLoader, + this.urlPath); } public virtual ActionResult Create(IEnumerable siteMapCacheKeys, string baseUrl, string siteMapUrlTemplate) @@ -84,7 +88,8 @@ public virtual ActionResult Create(IEnumerable siteMapCacheKeys, string siteMapCacheKeys, baseUrl, siteMapUrlTemplate, - this.siteMapLoader); + this.siteMapLoader, + this.urlPath); } public ActionResult Create(int page, IEnumerable siteMapCacheKeys, string baseUrl, string siteMapUrlTemplate) @@ -95,7 +100,8 @@ public ActionResult Create(int page, IEnumerable siteMapCacheKeys, strin siteMapCacheKeys, baseUrl, siteMapUrlTemplate, - this.siteMapLoader); + this.siteMapLoader, + this.urlPath); } public virtual ActionResult Create(ISiteMapNode rootNode) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 DefaultSiteMapCacheKeys