Skip to content

Commit

Permalink
Closes #365, in a web farm or cloud environment, the "HTTP_HOST" head…
Browse files Browse the repository at this point in the history
…er 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.
  • Loading branch information
NightOwl888 committed Nov 2, 2014
1 parent 710a155 commit 06b3f23
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 06b3f23

Please sign in to comment.