Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
manage Language Browser detection redirection
better 404 managment
  • Loading branch information
Sacha Trauwaen committed Feb 14, 2014
1 parent 372b2dd commit 4efa77a
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 46 deletions.
5 changes: 3 additions & 2 deletions Components/CacheController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public UrlRule GetModuleRule(string CultureCode, int TabId, string Url)
//without tabid
if (rule == null)
{
rule = GetFirstRule(rules, CultureCode);
var tabRules = rules.Where(r => r.TabId == 0); // added 7/2/2014
rule = GetFirstRule(tabRules, CultureCode);
}
if (rule == null)
{
Expand Down Expand Up @@ -288,7 +289,7 @@ private UrlRule GetRedirectModuleRule(string CultureCode, int TabId, string Url)
if (rule == null)
{
// try to find a rule with de begin of url match a rule RedirectDestination
rules = _rules.Where(r => r.RuleType == UrlRuleType.Module && Url.StartsWith(r.RedirectDestination) && r.Action == UrlRuleAction.Rewrite /*&& r.RemoveTab == RemoveTab*/);
rules = _rules.Where(r => r.RuleType == UrlRuleType.Module && Url.StartsWith(r.RedirectDestination+"/") && r.Action == UrlRuleAction.Rewrite /*&& r.RemoveTab == RemoveTab*/);
//with tabid
if (TabId != Null.NullInteger)
{
Expand Down
1 change: 1 addition & 0 deletions HttpModules/FriendlyUrlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ private static UrlRule GetTabUrl(int PortalId, string CultureCode, int TabId)

private static UrlRule GetTabUrl(int PortalId, string CultureCode, string parameter)
{
parameter = parameter.ToLower();
var rule = getRules(PortalId, CultureCode).FirstOrDefault(r => r.RuleType == UrlRuleType.Tab && r.Parameters == parameter);
if (rule == null && !string.IsNullOrEmpty(CultureCode))
{
Expand Down
2 changes: 1 addition & 1 deletion HttpModules/RewriterUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static void RewriteUrl(HttpContext context, string sendToUrl)
internal static void RewriteUrl(HttpContext context, string sendToUrl, ref string sendToUrlLessQString, ref string filePath)
{
string debugMsg = "{0}, {1}";
context.Response.AppendHeader("X-StbUrlRewriter-Debug", string.Format(debugMsg, context.Request.RawUrl, sendToUrl));
context.Response.AppendHeader("X-OpenUrlRewriter-Debug", string.Format(debugMsg, context.Request.RawUrl, sendToUrl));

//System.Diagnostics.Debug.WriteLine(context.Request.RawUrl);

Expand Down
45 changes: 30 additions & 15 deletions HttpModules/UrlRewriteModule.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2012
// by DotNetNuke Corporation
// Satrabel - http://www.satrabel.be
// Copyright (c) 2002-2014
// by Satrabel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
Expand Down Expand Up @@ -109,7 +109,7 @@ private void RewriteUrl(HttpApplication app, out string portalAlias) {

if (action.DoNotFound)
{
string strURL = "ErrorPage.aspx?status=404&error=CustomRule";
//string strURL = "ErrorPage.aspx?status=404&error=CustomRule";
app.Response.Clear();
app.Response.StatusCode = 404;
app.Response.Status = "404 Not Found";
Expand All @@ -119,21 +119,36 @@ private void RewriteUrl(HttpApplication app, out string portalAlias) {
if (TabId404 != -1)
{
//TabInfo errTab = tc.GetTab(errTabId, result.PortalId, true);
strURL = Globals.glbDefaultPage + "?TabId=" + TabId404.ToString();
string strURL = Globals.glbDefaultPage + "?TabId=" + TabId404.ToString();
var ps = new PortalSettings(TabId404, objPortalAlias);
app.Context.Items.Add("PortalSettings", ps);
}

if (app.Context.User == null)
{
app.Context.User = Thread.CurrentPrincipal;
if (app.Context.User == null)
{
app.Context.User = Thread.CurrentPrincipal;
}
app.Response.TrySkipIisCustomErrors = true;
//spoof the basePage object so that the client dependency framework
//is satisfied it's working with a page-based handler
IHttpHandler spoofPage = new CDefault();
app.Context.Handler = spoofPage;
app.Context.Server.Transfer("~/" + strURL, true);

}
else {
const string errorPageHtmlHeader = @"<html><head><title>404 Page not found </title></head><body>";
const string errorPageHtmlFooter = @"</body></html>";
var errorPageHtml = new StringWriter();
errorPageHtml.Write("<br> 404 Fle not found ");
errorPageHtml.Write("<br> Raison : " + action.Raison);
errorPageHtml.Write("<div style='font-weight:bolder'>Administrators</div>");
errorPageHtml.Write("<div>Change this message by configuring a specific 404 Error Page.</div>");
errorPageHtml.Write(string.Format("<a href=\"//{0}\">Goto website</a>", objPortalAlias.HTTPAlias));
app.Response.Write(errorPageHtmlHeader);
app.Response.Write(errorPageHtml.ToString());
app.Response.Write(errorPageHtmlFooter);
}
app.Response.TrySkipIisCustomErrors = true;
//881 : spoof the basePage object so that the client dependency framework
//is satisfied it's working with a page-based handler
IHttpHandler spoofPage = new CDefault();
app.Context.Handler = spoofPage;
app.Context.Server.Transfer("~/" + strURL, true);

app.Response.End();
} else if (action.DoRedirect) {
app.Context.Items.Add("UrlRewrite:RedirectUrl", action.RedirectUrl);
Expand Down
66 changes: 45 additions & 21 deletions HttpModules/UrlRewriteModuleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,47 @@ private static void RewriteUrl(HttpApplication app, Uri url, out string portalAl
#endif
else
{
PortalController pc = new PortalController();
Locale DefaultLocale = LocaleController.Instance.GetDefaultLocale(portalID);
PortalInfo objPortal = new PortalController().GetPortal(portalID, DefaultLocale.Code);

string sendToUrl = "~/" + Globals.glbDefaultPage + "?TabID=" + objPortal.HomeTabId;
if (dicLocales.Count > 1)
string ActiveLanguage = PortalController.GetActivePortalLanguage(portalID);
if (ActiveLanguage != DefaultLocale.Code) // Browser language detection
{
sendToUrl = sendToUrl + "&language=" + objPortal.DefaultLanguage;
}
PortalInfo objPortal = pc.GetPortal(portalID, ActiveLanguage);
var portalSettings = new PortalSettings(objPortal.HomeTabId, objPortalAlias);

if (!string.IsNullOrEmpty(action.QueryUrl))
{
sendToUrl = sendToUrl + action.QueryUrl.Replace('?', '&');
app.Context.Items.Add("UrlRewrite:OriginalUrl", app.Request.Url.AbsoluteUri);
string HomeUrl = Globals.NavigateURL(objPortal.HomeTabId, false, portalSettings, "", ActiveLanguage);
app.Context.Items.Remove("UrlRewrite:OriginalUrl");
action.DoRedirect = true;
action.Raison += "+Active language";
action.Status = 302;
action.RedirectHomePage = true;
action.RedirectUrl = HomeUrl;
return;
}
if (app != null)
else
{
app.Context.Items.Add("UrlRewrite:RewriteUrl", RewriterUtils.ResolveUrl(applicationPath, sendToUrl));
PortalInfo objPortal = pc.GetPortal(portalID, DefaultLocale.Code);

string sendToUrl = "~/" + Globals.glbDefaultPage + "?TabID=" + objPortal.HomeTabId;
if (dicLocales.Count > 1)
{
sendToUrl = sendToUrl + "&language=" + objPortal.DefaultLanguage;
}

if (!string.IsNullOrEmpty(action.QueryUrl))
{
sendToUrl = sendToUrl + action.QueryUrl.Replace('?', '&');
}
if (app != null)
{
app.Context.Items.Add("UrlRewrite:RewriteUrl", RewriterUtils.ResolveUrl(applicationPath, sendToUrl));
}
//RewriterUtils.RewriteUrl(app.Context, sendToUrl);
action.DoReWrite = true;
action.RewriteUrl = sendToUrl;
return;
}
//RewriterUtils.RewriteUrl(app.Context, sendToUrl);
action.DoReWrite = true;
action.RewriteUrl = sendToUrl;
return;
}
}

Expand All @@ -241,7 +261,6 @@ private static void RewriteUrl(HttpApplication app, Uri url, out string portalAl
{
app.Context.Items.Add("UrlRewrite:RewriteUrl", RewriterUtils.ResolveUrl(applicationPath, sendToUrl));
}
//RewriterUtils.RewriteUrl(app.Context, sendToUrl);
action.DoReWrite = true;
action.RewriteUrl = sendToUrl;
return;
Expand Down Expand Up @@ -367,8 +386,11 @@ private static void RewriteUrl(HttpApplication app, Uri url, out string portalAl
{
return;
}
action.Raison = "Page not found";
action.DoNotFound = true;
//if (UrlRewiterSettings.IsManage404(objPortalAlias.PortalID))
{
action.Raison = "Page not found";
action.DoNotFound = true;
}

/*
tabPath = tabPath.Replace("/", "//");
Expand Down Expand Up @@ -437,7 +459,9 @@ private static bool IsSpecialPage(Uri Url, string PhysicalPath, string RawUrl, s
{
return true;
}
if (Url.LocalPath.ToLower().EndsWith(".aspx") && !Url.LocalPath.ToLower().EndsWith(Globals.glbDefaultPage.ToLower()))
//if (Url.LocalPath.ToLower().EndsWith(".aspx") && !Url.LocalPath.ToLower().EndsWith(Globals.glbDefaultPage.ToLower()))

if ((Directory.Exists(PhysicalPath) || File.Exists(PhysicalPath)) && !Url.LocalPath.ToLower().EndsWith(Globals.glbDefaultPage.ToLower()))
{
return true;
}
Expand Down Expand Up @@ -1073,7 +1097,7 @@ private static bool ProcessCustomRules(CacheController cacheCtrl, string Applica
Match objMatch = Regex.Match(requestedPath, pattern, RegexOptions.IgnoreCase);

//if there is a match
if ((objMatch.Success))
if (objMatch.Success /* && (string.IsNullOrEmpty(rule.Parameters) || rule.Parameters == strQueryString) */ )
{
//create a new URL using the SendTo regex value
sendTo = RewriterUtils.ResolveUrl(ApplicationPath, Regex.Replace(requestedPath, pattern, rule.RedirectDestination, RegexOptions.IgnoreCase));
Expand All @@ -1087,7 +1111,7 @@ private static bool ProcessCustomRules(CacheController cacheCtrl, string Applica
}

//if a match was found to the urlrewrite rules
if (ruleFound != null)
if (ruleFound != null /*&& string.IsNullOrEmpty(ruleFound.Parameters)*/ )
{
if (!String.IsNullOrEmpty(strQueryString))
{
Expand Down
17 changes: 14 additions & 3 deletions Providers/UrlRuleProviders/UrlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
using DotNetNuke.ComponentModel;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Instrumentation;
using Satrabel.HttpModules.Config;

#endregion

Expand Down Expand Up @@ -69,10 +71,19 @@ public List<UrlRule> BuildUrlMap(int PortalId)
{
// Get all urls from provider
List<UrlRule> urls = _provider.GetRules(PortalId);
foreach (UrlRule url in urls)
{
allUrls.Add(url);
if (urls != null)
{
foreach (UrlRule url in urls)
{
allUrls.Add(url);
}
}
else
{
DnnLogger logger = DnnLogger.GetClassLogger(typeof(UrlRuleConfiguration));
logger.Error("No urls for PortalId " + PortalId);
}

}
}
return allUrls;
Expand Down
2 changes: 1 addition & 1 deletion Providers/UrlRuleProviders/UrlRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public bool IsMatchRedirectDestination(string ModuleUrl)
public string Replace(string ModuleQueryString, string PageName)
{

string internRegExp = GenerateRegExp(Parameters);
string internRegExp = GenerateRegExp(Parameters.ToLower());
string externRegExp = Url.Replace("[pagename]", PageName).Replace("{", "${").Replace("[", "${").Replace("]", "}");
Regex regex = new Regex(internRegExp, RegexOptions.IgnoreCase);
if (regex.IsMatch(ModuleQueryString))
Expand Down
2 changes: 1 addition & 1 deletion Providers/UrlRuleProviders/UrlRuleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected static string CleanupUrl(string Url)
}
else if (@".[]|:;`%\\""".Contains(ch))
ch = "";
else if (@" &$+,/=?@~#<>()¿¡«»!'’".Contains(ch))
else if (@" &$+,/=?@~#<>()¿¡«»!'’".Contains(ch))
ch = replaceWith;
else
{
Expand Down
2 changes: 1 addition & 1 deletion UrlRule_View.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {

GridView1.DataSource = UrlRuleController.GetUrlRules(PortalId).OrderByDescending(r=> r.RuleType);
GridView1.DataSource = UrlRuleController.GetUrlRules(PortalId).OrderByDescending(r=> r.RuleType).ThenByDescending(r => r.Parameters);
GridView1.DataBind();


Expand Down
2 changes: 1 addition & 1 deletion View.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private void ShowCache()
gvCache.DataSource = stats;
gvCache.DataBind();

var clashes = from r in Rules
var clashes = from r in Rules /* .Where(r=> r.RuleType != UrlRuleType.Custom)*/

group r by new { r.RuleTypeString, r.CultureCode, r.TabId, r.Url } into g
where g.Count() > 1
Expand Down

0 comments on commit 4efa77a

Please sign in to comment.