Fixed all redirections with appropriate host (as configured).
This commit is contained in:
parent
8c35eed690
commit
191d903b2d
13 changed files with 149 additions and 124 deletions
|
@ -2601,7 +2601,7 @@ namespace ScrewTurn.Wiki {
|
|||
string login = Exchanger.ResourceExchanger.GetResource("Login");
|
||||
StringBuilder sb = new StringBuilder(200);
|
||||
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(login);
|
||||
sb.Append("\">");
|
||||
|
@ -2618,7 +2618,7 @@ namespace ScrewTurn.Wiki {
|
|||
string login = Exchanger.ResourceExchanger.GetResource("Logout");
|
||||
StringBuilder sb = new StringBuilder(200);
|
||||
sb.Append("<a href=\"");
|
||||
sb.Append(UrlTools.BuildUrl("Login.aspx?ForceLogout=1&Redirect=", Tools.UrlEncode(HttpContext.Current.Request.Url.ToString())));
|
||||
sb.Append(UrlTools.BuildUrl("Login.aspx?ForceLogout=1&Redirect=", Tools.UrlEncode(Tools.GetCurrentUrlFixed())));
|
||||
sb.Append("\" class=\"systemlink\" title=\"");
|
||||
sb.Append(login);
|
||||
sb.Append("\">");
|
||||
|
|
|
@ -1019,7 +1019,7 @@ namespace ScrewTurn.Wiki {
|
|||
/// </summary>
|
||||
/// <returns>The URL.</returns>
|
||||
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("/")) {
|
||||
int index = url.LastIndexOf("/");
|
||||
if(index != -1) url = url.Substring(0, index + 1);
|
||||
|
|
|
@ -326,6 +326,31 @@ namespace ScrewTurn.Wiki {
|
|||
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>
|
||||
/// Executes URL-encoding, avoiding to use '+' for spaces.
|
||||
/// </summary>
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace ScrewTurn.Wiki {
|
|||
string queryString = ""; // Empty or begins with ampersand, not question mark
|
||||
try {
|
||||
// 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 { }
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace ScrewTurn.Wiki {
|
|||
/// </summary>
|
||||
public static void RedirectToLoginIfNeeded() {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ namespace ScrewTurn.Wiki {
|
|||
}
|
||||
|
||||
protected void btnAutoWikiUrl_Click(object sender, EventArgs e) {
|
||||
string url = Request.Url.ToString();
|
||||
string url = Tools.GetCurrentUrlFixed();
|
||||
// Assume the URL contains AdminConfig.aspx
|
||||
url = url.Substring(0, url.ToLowerInvariant().IndexOf("adminconfig.aspx"));
|
||||
txtMainUrl.Text = url;
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace ScrewTurn.Wiki {
|
|||
currentUsername, currentGroups);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace ScrewTurn.Wiki {
|
|||
bool canManageDiscussion = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ManageDiscussion, currentUsername, currentGroups);
|
||||
|
||||
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"));
|
||||
}
|
||||
attachmentViewer.Visible = canDownloadAttachments;
|
||||
|
|
|
@ -180,14 +180,14 @@ namespace ScrewTurn.Wiki {
|
|||
if(currentPage == null) {
|
||||
// Check permissions for creating new pages
|
||||
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 {
|
||||
// Check permissions for editing current page
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace ScrewTurn.Wiki {
|
|||
private void LogError(Exception ex) {
|
||||
//if(ex.InnerException != null) ex = ex.InnerException;
|
||||
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,
|
||||
ScrewTurn.Wiki.PluginFramework.EntryType.Error, ScrewTurn.Wiki.Log.SystemUsername);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ namespace ScrewTurn.Wiki {
|
|||
LogError(ex);
|
||||
string url = "";
|
||||
try {
|
||||
url = HttpContext.Current.Request.Url.ToString();
|
||||
url = Tools.GetCurrentUrlFixed();
|
||||
}
|
||||
catch { }
|
||||
EmailTools.NotifyError(ex, url);
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace ScrewTurn.Wiki {
|
|||
languageSelector.SelectedLanguage = lang;
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace ScrewTurn.Wiki {
|
|||
lnkMainPage.NavigateUrl = nspace + "Default.aspx";
|
||||
|
||||
if(!Page.IsPostBack) {
|
||||
string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : "";
|
||||
string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.FixHost().ToString() : "";
|
||||
if(!string.IsNullOrEmpty(referrer)) {
|
||||
lnkPreviousPage.Visible = true;
|
||||
lnkPreviousPage.NavigateUrl = referrer;
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace ScrewTurn.Wiki {
|
|||
lblTitle.Text = lblTitle.Text.Replace("##NAME##", Users.GetDisplayName(currentUser));
|
||||
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue