Fixed handling of multiple URL hosts in multi tenancy UI.

This commit is contained in:
Daniel Stolt
2015-07-16 12:29:29 +01:00
parent fe5b591b21
commit 1471ab8cd5
2 changed files with 19 additions and 15 deletions

View File

@@ -1,26 +1,30 @@
using System.Web.Mvc; using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.Environment.Configuration; using Orchard.Environment.Configuration;
namespace Orchard.MultiTenancy.Extensions { namespace Orchard.MultiTenancy.Extensions {
public static class UrlHelperExtensions { public static class UrlHelperExtensions {
public static string Tenant(this UrlHelper urlHelper, ShellSettings tenantShellSettings) { public static string Tenant(this UrlHelper urlHelper, ShellSettings tenantShellSettings) {
var requestUrlHost = tenantShellSettings.RequestUrlHost.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).First();
//info: (heskew) might not keep the port/vdir insertion around beyond... //info: (heskew) might not keep the port/vdir insertion around beyond...
var port = string.Empty; var port = string.Empty;
string host = urlHelper.RequestContext.HttpContext.Request.Headers["Host"]; var host = urlHelper.RequestContext.HttpContext.Request.Headers["Host"];
if (host.Contains(":")) if (host.Contains(":"))
port = host.Substring(host.IndexOf(":")); port = host.Substring(host.IndexOf(":"));
var result = string.Format("{0}://{1}", var result = String.Format("{0}://{1}",
urlHelper.RequestContext.HttpContext.Request.Url.Scheme, urlHelper.RequestContext.HttpContext.Request.Url.Scheme,
!string.IsNullOrEmpty(tenantShellSettings.RequestUrlHost) !String.IsNullOrEmpty(requestUrlHost) ? requestUrlHost + port : host);
? tenantShellSettings.RequestUrlHost + port : host);
var applicationPath = urlHelper.RequestContext.HttpContext.Request.ApplicationPath; var applicationPath = urlHelper.RequestContext.HttpContext.Request.ApplicationPath;
if (!string.IsNullOrEmpty(applicationPath) && !string.Equals(applicationPath, "/")) if (!String.IsNullOrEmpty(applicationPath) && applicationPath != "/")
result += applicationPath; result += applicationPath;
if (!string.IsNullOrEmpty(tenantShellSettings.RequestUrlPrefix)) if (!String.IsNullOrEmpty(tenantShellSettings.RequestUrlPrefix))
result += "/" + tenantShellSettings.RequestUrlPrefix; result += "/" + tenantShellSettings.RequestUrlPrefix;
return result; return result;

View File

@@ -16,9 +16,9 @@
<h2>@Model.Name</h2> <h2>@Model.Name</h2>
</div> </div>
<div> <div>
<label for="@Html.FieldIdFor(m => m.RequestUrlHost)">@T("Host")</label> <label for="@Html.FieldIdFor(m => m.RequestUrlHost)">@T("URL host")</label>
@Html.TextBoxFor(m => m.RequestUrlHost, new { @class = "text medium" }) @Html.TextBoxFor(m => m.RequestUrlHost, new { @class = "text medium" })
<span class="hint">@T("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\"")</span> <span class="hint">@T("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\". Multiple hosts can be separated by a comma.")</span>
</div> </div>
<div> <div>
<label for="@Html.FieldIdFor(m => m.RequestUrlPrefix)">@T("URL prefix")</label> <label for="@Html.FieldIdFor(m => m.RequestUrlPrefix)">@T("URL prefix")</label>