From ffa6f12f6b2320e5aed861abd4673b7cccc3e6f9 Mon Sep 17 00:00:00 2001 From: Dario Solera Date: Wed, 5 Jan 2011 14:19:41 +0000 Subject: [PATCH] Fixed more bugs in FixHost method. --- AssemblyVersion.cs | 4 ++-- Core/Tools.cs | 23 +++++++++++++++---- WebApplication/AdminConfig.aspx | 2 +- .../App_LocalResources/AdminConfig.aspx.resx | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/AssemblyVersion.cs b/AssemblyVersion.cs index ac96070..5e0185e 100644 --- a/AssemblyVersion.cs +++ b/AssemblyVersion.cs @@ -16,5 +16,5 @@ using System.Reflection; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("3.0.4.571")] -[assembly: AssemblyFileVersion("3.0.4.571")] \ No newline at end of file +[assembly: AssemblyVersion("3.0.4.572")] +[assembly: AssemblyFileVersion("3.0.4.572")] \ No newline at end of file diff --git a/Core/Tools.cs b/Core/Tools.cs index 0c1bfee..5438129 100644 --- a/Core/Tools.cs +++ b/Core/Tools.cs @@ -327,16 +327,31 @@ namespace ScrewTurn.Wiki { return result; } + private static string CleanupPort(string url, string host) { + if(!url.Contains(host)) { + int colonIndex = host.IndexOf(":"); + if(colonIndex != -1) { + host = host.Substring(0, colonIndex); + } + } + + return host; + } + /// - /// Automatically replaces the host in the URL with that obtained from . + /// Automatically replaces the host and port in the URL with those obtained from . /// /// The URL. - /// The URL with fixed host. + /// The URL with fixed host and port. public static Uri FixHost(this Uri url) { // Make sure the host is replaced only once string originalUrl = url.ToString(); - string originalHost = url.Host; - string newHost = Settings.GetMainUrl().Host; + string originalHost = url.GetComponents(UriComponents.HostAndPort, UriFormat.Unescaped); + Uri mainUrl = Settings.GetMainUrl(); + string newHost = mainUrl.GetComponents(UriComponents.HostAndPort, UriFormat.Unescaped); + + originalHost = CleanupPort(originalUrl, originalHost); + newHost = CleanupPort(mainUrl.ToString(), newHost); int hostIndex = originalUrl.IndexOf(originalHost); string newUrl = originalUrl.Substring(0, hostIndex) + newHost + originalUrl.Substring(hostIndex + originalHost.Length); diff --git a/WebApplication/AdminConfig.aspx b/WebApplication/AdminConfig.aspx index 585af8c..a814b47 100644 --- a/WebApplication/AdminConfig.aspx +++ b/WebApplication/AdminConfig.aspx @@ -45,7 +45,7 @@ ( - - used for email communications + used for email communications and redirects Wiki title