Fixed all redirections with appropriate host (as configured).

This commit is contained in:
Dario Solera 2010-12-29 14:07:49 +00:00
parent 8c35eed690
commit 191d903b2d
13 changed files with 149 additions and 124 deletions

View file

@ -2601,7 +2601,7 @@ namespace ScrewTurn.Wiki {
string login = Exchanger.ResourceExchanger.GetResource("Login"); string login = Exchanger.ResourceExchanger.GetResource("Login");
StringBuilder sb = new StringBuilder(200); StringBuilder sb = new StringBuilder(200);
sb.Append("<a href=\""); sb.Append("<a href=\"");
sb.Append(UrlTools.BuildUrl("Login.aspx?Redirect=", Tools.UrlEncode(HttpContext.Current.Request.Url.ToString()))); sb.Append(UrlTools.BuildUrl("Login.aspx?Redirect=", Tools.UrlEncode(Tools.GetCurrentUrlFixed())));
sb.Append("\" class=\"systemlink\" title=\""); sb.Append("\" class=\"systemlink\" title=\"");
sb.Append(login); sb.Append(login);
sb.Append("\">"); sb.Append("\">");
@ -2618,7 +2618,7 @@ namespace ScrewTurn.Wiki {
string login = Exchanger.ResourceExchanger.GetResource("Logout"); string login = Exchanger.ResourceExchanger.GetResource("Logout");
StringBuilder sb = new StringBuilder(200); StringBuilder sb = new StringBuilder(200);
sb.Append("<a href=\""); sb.Append("<a href=\"");
sb.Append(UrlTools.BuildUrl("Login.aspx?ForceLogout=1&amp;Redirect=", Tools.UrlEncode(HttpContext.Current.Request.Url.ToString()))); sb.Append(UrlTools.BuildUrl("Login.aspx?ForceLogout=1&amp;Redirect=", Tools.UrlEncode(Tools.GetCurrentUrlFixed())));
sb.Append("\" class=\"systemlink\" title=\""); sb.Append("\" class=\"systemlink\" title=\"");
sb.Append(login); sb.Append(login);
sb.Append("\">"); sb.Append("\">");

View file

@ -1019,7 +1019,7 @@ namespace ScrewTurn.Wiki {
/// </summary> /// </summary>
/// <returns>The URL.</returns> /// <returns>The URL.</returns>
private static string GetCurrentRequestMainUrl() { private static string GetCurrentRequestMainUrl() {
string url = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path); string url = HttpContext.Current.Request.Url.FixHost().GetLeftPart(UriPartial.Path);
if(!url.EndsWith("/")) { if(!url.EndsWith("/")) {
int index = url.LastIndexOf("/"); int index = url.LastIndexOf("/");
if(index != -1) url = url.Substring(0, index + 1); if(index != -1) url = url.Substring(0, index + 1);

View file

@ -326,6 +326,31 @@ namespace ScrewTurn.Wiki {
return result; return result;
} }
/// <summary>
/// Automatically replaces the host in the URL with that obtained from <see cref="Settings.GetMainUrl"/>.
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>The URL with fixed host.</returns>
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;
int hostIndex = originalUrl.IndexOf(originalHost);
string newUrl = originalUrl.Substring(0, hostIndex) + newHost + originalUrl.Substring(hostIndex + originalHost.Length + 1);
return new Uri(newUrl);
}
/// <summary>
/// Gets the current request's URL, with the host already fixed.
/// </summary>
/// <returns>The current URL.</returns>
public static string GetCurrentUrlFixed() {
return HttpContext.Current.Request.Url.FixHost().ToString();
}
/// <summary> /// <summary>
/// Executes URL-encoding, avoiding to use '+' for spaces. /// Executes URL-encoding, avoiding to use '+' for spaces.
/// </summary> /// </summary>

View file

@ -51,7 +51,7 @@ namespace ScrewTurn.Wiki {
string queryString = ""; // Empty or begins with ampersand, not question mark string queryString = ""; // Empty or begins with ampersand, not question mark
try { try {
// This might throw exceptions if 3rd-party modules interfer with the request pipeline // This might throw exceptions if 3rd-party modules interfer with the request pipeline
queryString = HttpContext.Current.Request.Url.Query.Replace("?", "&"); queryString = HttpContext.Current.Request.Url.Query.Replace("?", "&"); // Host not used
} }
catch { } catch { }

View file

@ -37,7 +37,7 @@ namespace ScrewTurn.Wiki {
/// </summary> /// </summary>
public static void RedirectToLoginIfNeeded() { public static void RedirectToLoginIfNeeded() {
if(SessionFacade.LoginKey == null) { if(SessionFacade.LoginKey == null) {
UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(HttpContext.Current.Request.Url.ToString())); UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
} }
} }

View file

@ -306,7 +306,7 @@ namespace ScrewTurn.Wiki {
} }
protected void btnAutoWikiUrl_Click(object sender, EventArgs e) { protected void btnAutoWikiUrl_Click(object sender, EventArgs e) {
string url = Request.Url.ToString(); string url = Tools.GetCurrentUrlFixed();
// Assume the URL contains AdminConfig.aspx // Assume the URL contains AdminConfig.aspx
url = url.Substring(0, url.ToLowerInvariant().IndexOf("adminconfig.aspx")); url = url.Substring(0, url.ToLowerInvariant().IndexOf("adminconfig.aspx"));
txtMainUrl.Text = url; txtMainUrl.Text = url;

View file

@ -115,7 +115,7 @@ namespace ScrewTurn.Wiki {
currentUsername, currentGroups); currentUsername, currentGroups);
if(!canViewNamespace) { if(!canViewNamespace) {
if(SessionFacade.CurrentUsername == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(HttpContext.Current.Request.Url.ToString())); if(SessionFacade.CurrentUsername == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
else UrlTools.Redirect("AccessDenied.aspx"); else UrlTools.Redirect("AccessDenied.aspx");
} }
} }

View file

@ -51,7 +51,7 @@ namespace ScrewTurn.Wiki {
bool canManageDiscussion = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ManageDiscussion, currentUsername, currentGroups); bool canManageDiscussion = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ManageDiscussion, currentUsername, currentGroups);
if(!canView) { if(!canView) {
if(SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Request.Url.ToString())); if(SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
else UrlTools.Redirect(UrlTools.BuildUrl("AccessDenied.aspx")); else UrlTools.Redirect(UrlTools.BuildUrl("AccessDenied.aspx"));
} }
attachmentViewer.Visible = canDownloadAttachments; attachmentViewer.Visible = canDownloadAttachments;

View file

@ -180,14 +180,14 @@ namespace ScrewTurn.Wiki {
if(currentPage == null) { if(currentPage == null) {
// Check permissions for creating new pages // Check permissions for creating new pages
if(!canCreateNewPages) { if(!canCreateNewPages) {
if(SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Request.Url.ToString())); if(SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
else UrlTools.Redirect("AccessDenied.aspx"); else UrlTools.Redirect("AccessDenied.aspx");
} }
} }
else { else {
// Check permissions for editing current page // Check permissions for editing current page
if(!canEdit && !canEditWithApproval) { if(!canEdit && !canEditWithApproval) {
if(SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Request.Url.ToString())); if(SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
else UrlTools.Redirect("AccessDenied.aspx"); else UrlTools.Redirect("AccessDenied.aspx");
} }
} }

View file

@ -58,7 +58,7 @@ namespace ScrewTurn.Wiki {
private void LogError(Exception ex) { private void LogError(Exception ex) {
//if(ex.InnerException != null) ex = ex.InnerException; //if(ex.InnerException != null) ex = ex.InnerException;
try { try {
ScrewTurn.Wiki.Log.LogEntry(HttpContext.Current.Request.Url.ToString() + "\n" + ScrewTurn.Wiki.Log.LogEntry(Tools.GetCurrentUrlFixed() + "\n" +
ex.Source + " thrown " + ex.GetType().FullName + "\n" + ex.Message + "\n" + ex.StackTrace, ex.Source + " thrown " + ex.GetType().FullName + "\n" + ex.Message + "\n" + ex.StackTrace,
ScrewTurn.Wiki.PluginFramework.EntryType.Error, ScrewTurn.Wiki.Log.SystemUsername); ScrewTurn.Wiki.PluginFramework.EntryType.Error, ScrewTurn.Wiki.Log.SystemUsername);
} }
@ -83,7 +83,7 @@ namespace ScrewTurn.Wiki {
LogError(ex); LogError(ex);
string url = ""; string url = "";
try { try {
url = HttpContext.Current.Request.Url.ToString(); url = Tools.GetCurrentUrlFixed();
} }
catch { } catch { }
EmailTools.NotifyError(ex, url); EmailTools.NotifyError(ex, url);

View file

@ -44,7 +44,7 @@ namespace ScrewTurn.Wiki {
languageSelector.SelectedLanguage = lang; languageSelector.SelectedLanguage = lang;
if(Request["Redirect"] != null) UrlTools.Redirect(UrlTools.BuildUrl(Request["Redirect"])); if(Request["Redirect"] != null) UrlTools.Redirect(UrlTools.BuildUrl(Request["Redirect"]));
else if(Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString())) UrlTools.Redirect(UrlTools.BuildUrl(Request.UrlReferrer.ToString())); else if(Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString())) UrlTools.Redirect(UrlTools.BuildUrl(Request.UrlReferrer.FixHost().ToString()));
} }
} }

View file

@ -26,7 +26,7 @@ namespace ScrewTurn.Wiki {
lnkMainPage.NavigateUrl = nspace + "Default.aspx"; lnkMainPage.NavigateUrl = nspace + "Default.aspx";
if(!Page.IsPostBack) { if(!Page.IsPostBack) {
string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : ""; string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.FixHost().ToString() : "";
if(!string.IsNullOrEmpty(referrer)) { if(!string.IsNullOrEmpty(referrer)) {
lnkPreviousPage.Visible = true; lnkPreviousPage.Visible = true;
lnkPreviousPage.NavigateUrl = referrer; lnkPreviousPage.NavigateUrl = referrer;

View file

@ -33,7 +33,7 @@ namespace ScrewTurn.Wiki {
lblTitle.Text = lblTitle.Text.Replace("##NAME##", Users.GetDisplayName(currentUser)); lblTitle.Text = lblTitle.Text.Replace("##NAME##", Users.GetDisplayName(currentUser));
txtSubject.Text = Request["Subject"]; txtSubject.Text = Request["Subject"];
if(txtSubject.Text != "" && SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Request.Url.ToString())); if(txtSubject.Text != "" && SessionFacade.LoginKey == null) UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
} }
if(SessionFacade.LoginKey == null) pnlMessage.Visible = false; if(SessionFacade.LoginKey == null) pnlMessage.Visible = false;