/// (summary)
/// Generates port-agnostic link to an application via UWS Redirector.
/// (/summary)
/// (param name="appID")(/param)
/// (param name="host")
/// Optional. Host name or IP address to be used in the URL pointing to the UWS Recirector application.
/// If null, default host will be used. If set to "*IOS*", host will be in the format of "machinename.local" or "machinename",
/// depending on whether host machine is a member of a domain.
/// (/param)
/// (param name="optionalPathAndQueryString")Optional. A part to be appended to the redirection URL,
/// in case start page is different from web app's default document.(/param)
/// (param name="portOrder")Optional. Lists port number preference order.
/// Should be used when multiple non-80 and non-443 is used as listen addresses.(/param)
/// (returns)(/returns)
public
static
string
CreateAppRedirectLink(Guid appID,
string
host =
null
,
string
optionalPathAndQueryString =
null
,
params
ushort
[] portOrder)
{
const
string
autoIOShost =
"*IOS*"
;
if
(
string
.IsNullOrEmpty(host) || host == autoIOShost)
host = GetDefaultHost(forIOS: host == autoIOShost);
WebAppConfigEntry uwsRedirector = Metabase.FindApplication(AppPoolRegistrationHelper.LegacyCassiniExplorerAppID);
string
[] urls = uwsRedirector.GetBrowseUrls(host);
StringBuilder url =
new
StringBuilder();
url.Append(urls[0]);
url.AppendFormat(
"GoToApplication.aspx/{0}"
, appID.ToString().ToUpper());
if
(portOrder !=
null
)
{
foreach
(
ushort
port
in
portOrder)
url.AppendFormat(
",{0}"
, port);
}
url.Append(
"/"
);
if
(!
string
.IsNullOrEmpty(optionalPathAndQueryString))
url.Append(optionalPathAndQueryString.TrimStart(
'/'
));
return
url.ToString();
}