public static UrlRewiterSettings Current() { if (current == null) { ProviderConfiguration providerConfiguration = ProviderConfiguration.GetProviderConfiguration("friendlyUrl"); var objProvider = (DotNetNuke.Framework.Providers.Provider)providerConfiguration.Providers[providerConfiguration.DefaultProvider]; current = new UrlRewiterSettings(objProvider); } return(current); }
public static UrlRewiterSettings Current() { if (current == null) { ProviderConfiguration providerConfiguration = ProviderConfiguration.GetProviderConfiguration("friendlyUrl"); var objProvider = (DotNetNuke.Framework.Providers.Provider)providerConfiguration.Providers[providerConfiguration.DefaultProvider]; current = new UrlRewiterSettings(objProvider); } return current; }
public void OnPreRequestHandlerExecute(object sender, EventArgs e) { try { //First check if we are upgrading/installing or if it is a non-page request var app = (HttpApplication)sender; HttpRequest request = app.Request; //First check if we are upgrading/installing if (request.Url.LocalPath.ToLower().EndsWith("install.aspx") || request.Url.LocalPath.ToLower().EndsWith("upgradewizard.aspx") || request.Url.LocalPath.ToLower().EndsWith("installwizard.aspx")) { return; } //exit if a request for a .net mapping that isn't a content page is made i.e. axd if (request.Url.LocalPath.ToLower().EndsWith(".aspx") == false && request.Url.LocalPath.ToLower().EndsWith(".asmx") == false && request.Url.LocalPath.ToLower().EndsWith(".ashx") == false) { return; } if (request.HttpMethod != "GET") { return; } if (HttpContext.Current != null) { HttpContext context = HttpContext.Current; if ((context == null)) { return; } var page = context.Handler as DotNetNuke.Framework.CDefault; if ((page == null)) { return; } page.Load += OnPageLoad; try { int PortalId = (int)HttpContext.Current.Items["UrlRewrite:PortalId"]; if (UrlRewiterSettings.IsW3C(PortalId)) { //app.Response.Filter = new PageFilter(app.Response.Filter); ResponseFilterStream filter = new ResponseFilterStream(app.Response.Filter); filter.TransformString += W3CTransform.filter_TransformString; app.Response.Filter = filter; app.Response.AddHeader("X-UA-Compatible", "IE=edge"); } } catch { } } } catch (Exception ex) { /* * var objEventLog = new EventLogController(); * var objEventLogInfo = new LogInfo(); * objEventLogInfo.AddProperty("Analytics.AnalyticsModule", "OnPreRequestHandlerExecute"); * objEventLogInfo.AddProperty("ExceptionMessage", ex.Message); * objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString(); * objEventLog.AddLog(objEventLogInfo); * * Logger.Error(objEventLogInfo); */ Logger.Error(ex); } }
public void OnEndRequest(object s, EventArgs e) { if (s == null) { return; } var app = (HttpApplication)s; #if DEBUG try { Stopwatch timer = (Stopwatch)HttpContext.Current.Items["UrlRewrite:Timer"]; app.Response.AddHeader("X-OpenUrlRewriter-OnEndRequest", timer.Elapsed.TotalMilliseconds.ToString()); } catch { } #endif int PortalId = -1; try { PortalId = (int)HttpContext.Current.Items["UrlRewrite:PortalId"]; } catch { } if (PortalId == -1) { return; } if (!UrlRewiterSettings.IsLogEnabled(PortalId)) { return; } var server = app.Server; var request = app.Request; var response = app.Response; var requestedPath = app.Request.Url.AbsoluteUri; if (RewriterUtils.OmitFromRewriteProcessing(request.Url.LocalPath)) { return; } if (request.Url.LocalPath.ToLower().EndsWith("/install/install.aspx") || request.Url.LocalPath.ToLower().EndsWith("/install/upgradewizard.aspx") || request.Url.LocalPath.ToLower().EndsWith("/install/installwizard.aspx") || request.Url.LocalPath.ToLower().EndsWith("captcha.aspx") || request.Url.LocalPath.ToLower().EndsWith("scriptresource.axd") || request.Url.LocalPath.ToLower().EndsWith("webresource.axd")) { return; } try { string originalurl = ""; try { originalurl = HttpContext.Current.Items["UrlRewrite:OriginalUrl"].ToString(); } catch { } int TabId = -1; try { TabId = (int)HttpContext.Current.Items["UrlRewrite:TabId"]; } catch { } string RedirectUrl = ""; try { RedirectUrl = HttpContext.Current.Items["UrlRewrite:RedirectUrl"].ToString(); } catch { } string RewriteUrl = request.Url.ToString(); try { RewriteUrl = HttpContext.Current.Items["UrlRewrite:RewriteUrl"].ToString(); } catch { } var statusCode = response.StatusCode; var httpContext = HttpContext.Current; if (httpContext.Server.GetLastError() != null && httpContext.Server.GetLastError().GetBaseException() != null) { var lastException = HttpContext.Current.Server.GetLastError().GetBaseException(); var httpException = lastException as HttpException; if (httpException != null) { statusCode = httpException.GetHttpCode(); } } //Logger.Error("{0} : {1}", httpContext.Request.Url.AbsoluteUri, statusCode); //System.Diagnostics.Debug.WriteLine(originalurl + " : " + statusCode); string strSiteLogStorage = "D"; // Host.SiteLogStorage; int intSiteLogBuffer = 1; // Host.SiteLogBuffer; //int PortalId = PortalSettings.Current.PortalId; //int TabId = PortalSettings.Current.ActiveTab.TabID; string urlReferrer = ""; if (request.UrlReferrer != null) { urlReferrer = request.UrlReferrer.ToString(); } //log visit bool DoLog = true; if (PortalId == -1) { DoLog = false; } //UserInfo objUserInfo = UserController.GetCurrentUserInfo(); UserInfo objUserInfo = UserController.Instance.GetCurrentUserInfo(); if (!UrlRewiterSettings.IsLogAuthentificatedUsers(PortalId) && objUserInfo != null && objUserInfo.UserID != -1) { DoLog = false; } if (!UrlRewiterSettings.IsLogStatusCode200(PortalId) && statusCode == 200) { DoLog = false; } if (DoLog) { if (PortalId != -1 && UrlRewiterSettings.IsLogEachUrlOneTime(PortalId)) { //var UrlLogLst = UrlLogController.GetUrlLogByOriginalUrl(PortalId, originalurl); UrlLogController.DeleteUrlLogByOriginalUrl(PortalId, originalurl); } var objSiteLogs = new UrlLogController(); objSiteLogs.AddUrlLog(PortalId, objUserInfo.UserID, urlReferrer, RewriteUrl, originalurl, RedirectUrl, request.UserAgent, request.UserHostAddress, request.UserHostName, TabId, statusCode, intSiteLogBuffer, strSiteLogStorage); } } catch (Exception exc) { Logger.Error(exc); } }
private void OnPageLoad(object sender, EventArgs e) { try { //var page = (System.Web.UI.Page)sender; var page = sender as DotNetNuke.Framework.CDefault; if ((page == null)) { return; } HtmlMeta MetaRobots = (HtmlMeta)page.FindControl("MetaRobots"); if (MetaRobots != null) { if (UrlRewiterSettings.IsDisableSiteIndex(page.PortalSettings.PortalId)) { MetaRobots.Content = "NOINDEX, NOFOLLOW"; } else if (page.Request.QueryString["ctl"] != null) { string ctlQueryString = page.Request.QueryString["ctl"].ToLower(); if (ctlQueryString == "terms" && UrlRewiterSettings.IsDisableTermsIndex(page.PortalSettings.PortalId)) { MetaRobots.Content = "NOINDEX, NOFOLLOW"; /* * var Cache = page.Response.Cache; * Cache.SetCacheability(HttpCacheability.Public); * Cache.SetExpires(DateTime.Now.AddSeconds(20)); * Cache.SetMaxAge(TimeSpan.FromSeconds(20)); * Cache.SetValidUntilExpires(true); * Cache.SetLastModified(DateTime.Now); * Cache.VaryByParams.IgnoreParams = true; */ } else if (ctlQueryString == "privacy" && UrlRewiterSettings.IsDisablePrivacyIndex(page.PortalSettings.PortalId)) { MetaRobots.Content = "NOINDEX, NOFOLLOW"; } if (ctlQueryString == "login" || ctlQueryString == "register" || ctlQueryString == "sendpassword") { MetaRobots.Content = "NOINDEX, NOFOLLOW"; } } } if (page.Request.QueryString["ctl"] != null) { string ctlQueryString = page.Request.QueryString["ctl"].ToLower(); if (ctlQueryString == "login" || ctlQueryString == "register" || ctlQueryString == "sendpassword") { var url = HttpContext.Current.Items["UrlRewrite:OriginalUrl"].ToString(); //string url = page.Request.RawUrl; if (url.Contains('?')) { url = url.Remove(url.IndexOf('?')); } //Add Canonical <link> var canonicalLink = new HtmlLink(); canonicalLink.Href = url; canonicalLink.Attributes["rel"] = "canonical"; //todo check if there is already a canonicalLink // Add the HtmlLink to the Head section of the page. page.Header.Controls.Add(canonicalLink); } } /* * var CanonicalCtrl = new HtmlMeta(); * CanonicalCtrl.Name = ""; * CanonicalCtrl.Content = sContent * page.Header.Controls.Add(CanonicalCtrl) */ Dictionary <string, Locale> .ValueCollection Locales; if (PortalSettings.Current.ContentLocalizationEnabled) { Locales = LocaleController.Instance.GetPublishedLocales(PortalSettings.Current.PortalId).Values; } else { Locales = LocaleController.Instance.GetLocales(PortalSettings.Current.PortalId).Values; } if (Locales.Count > 1) { foreach (Locale loc in Locales) { //locales.Add(loc.Code, loc); // <link rel="alternate" hreflang="en-gb" href="http://en-gb.example.com/page.html" /> string LocaleUrl; if (Locales.Count(l => l.Code.Substring(0, 2) == loc.Code.Substring(0, 2)) > 1) { LocaleUrl = loc.Code; } else { LocaleUrl = loc.Code.Substring(0, 2); } bool CanViewPage; var altLink = new HtmlLink(); altLink.Href = newUrl(loc.Code, out CanViewPage); altLink.Attributes["rel"] = "alternate"; altLink.Attributes["hreflang"] = LocaleUrl; // Add the HtmlLink to the Head section of the page. if (CanViewPage) { page.Header.Controls.Add(altLink); } } /* * if (PortalSettings.Current.ActiveTab.TabID == PortalSettings.Current.HomeTabId) * { * var altLink = new HtmlLink(); * altLink.Href = page.Request.Url.Scheme + "://" + PortalSettings.Current.PortalAlias.HTTPAlias; * altLink.Attributes["rel"] = "alternate"; * altLink.Attributes["hreflang"] = "x-default"; * page.Header.Controls.Add(altLink); * } */ } } catch (Exception ex) { Logger.Error(ex); } }