From 06b3f23ac17785799028bd7db27a5a7b61c44a12 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 2 Nov 2014 12:45:24 +0700 Subject: [PATCH] Closes #365, in a web farm or cloud environment, the "HTTP_HOST" header is what provides the application with the host name. When it exists, it should be favored over the request.Url.DnsSafeHost property to get the host name. --- .../Caching/SiteMapCacheKeyGenerator.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Caching/SiteMapCacheKeyGenerator.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Caching/SiteMapCacheKeyGenerator.cs index 5afbf44f..83bd5115 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Caching/SiteMapCacheKeyGenerator.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Caching/SiteMapCacheKeyGenerator.cs @@ -26,14 +26,29 @@ IMvcContextFactory mvcContextFactory public virtual string GenerateKey() { - var context = mvcContextFactory.CreateHttpContext(); var builder = new StringBuilder(); builder.Append("sitemap://"); - builder.Append(context.Request.Url.DnsSafeHost); + builder.Append(this.GetHostName()); builder.Append("/"); + return builder.ToString(); } #endregion + + protected virtual string GetHostName() + { + var context = this.mvcContextFactory.CreateHttpContext(); + var request = context.Request; + + // In a cloud or web farm environment, use the HTTP_HOST + // header to derive the host name. + if (request.ServerVariables["HTTP_HOST"] != null) + { + return request.ServerVariables["HTTP_HOST"]; + } + + return request.Url.DnsSafeHost; + } } }