/// <summary> /// Use this event handler to perform operations like update /// the page meta tags , web analytics, etc /// </summary> /// <param name="e">Not used</param> protected override void OnPreRenderComplete(EventArgs e) { // Ideally we would load the trailing Stylesheests and JavaScript in OnInitComplete // or similar. The problem is, we can't guarantee that all the other code will get // it right. So we set up the trailing stuff here instead. InsertFooterStyleSheetsJavascriptsReferences(); base.OnPreRenderComplete(e); SetTitle(); InsertCanonicalURL(); InsertPageMetaData(); InsertPageLinkRels(); InsertBodyTagAttributes(); InsertHTMLTagAttributes(); //Set the form action so it does not post back to the page template path. if (this.Form != null) { NciUrl formAction = this.PageAssemblyInstruction.GetUrl("PostBackURL"); if (formAction == null || string.IsNullOrEmpty(formAction.ToString())) { //Log Error } else { this.Form.Action = formAction.ToString(); } } }
/// <summary> /// This sets up the Original Pretty URL, the current full URL and the app path /// </summary> private void SetupUrls() { //We want to use the PURL for this item. //NOTE: THIS NciUrl purl = this.PageInstruction.GetUrl(PageAssemblyInstructionUrls.PrettyUrl); if (purl == null || string.IsNullOrWhiteSpace(purl.ToString())) { throw new Exception("DynamicTrialListingPageDiseaseControl requires current PageAssemblyInstruction to provide its PrettyURL through GetURL. PrettyURL is null or empty."); } //It is expected that this is pure and only the pretty URL of this page. //This means that any elements on the same page as this app should NOT overwrite the //PrettyURL URL Filter. this.PrettyUrl = purl.ToString(); //Now, that we have the PrettyURL, let's figure out what the app paths are... NciUrl currURL = new NciUrl(); currURL.SetUrl(HttpContext.Current.Request.RawUrl); currURL.SetUrl(currURL.UriStem); //Make sure this URL starts with the pretty url if (currURL.UriStem.ToLower().IndexOf(this.PrettyUrl.ToLower()) != 0) { throw new Exception(String.Format("JSApplicationProxy: Cannot Determine App Path for Page, {0}, with PrettyURL {1}.", currURL.UriStem, PrettyUrl)); } this.CurrentUrl = currURL; }
/// <summary> /// Gets the View URL for an ID /// </summary> /// <param name="id"></param> /// <returns></returns> public string GetDetailedViewUrl(string id) { NciUrl url = new NciUrl(); url.SetUrl(string.Format(this.BaseConfig.DetailedViewPagePrettyUrlFormatter, id)); return(url.ToString()); }
public string GetPagerUrl(NciUrl basePageUrl, string first, string page) { NciUrl pagerUrl = basePageUrl; if(!pagerUrl.QueryParameters.ContainsKey("first")) { pagerUrl.QueryParameters.Add("first", first); } else { pagerUrl.QueryParameters.Remove("first"); pagerUrl.QueryParameters.Add("first", first); } if (!pagerUrl.QueryParameters.ContainsKey("page")) { pagerUrl.QueryParameters.Add("page", page); } else { pagerUrl.QueryParameters.Remove("page"); pagerUrl.QueryParameters.Add("page", page); } return pagerUrl.ToString(); }
/// <summary> /// Gets the search parameter Query items for print URL. /// </summary> /// <returns></returns> public string GetSearchParamsForPrint() { //Convert the current search parameters into a NciUrl NciUrl paramsUrl = CTSSearchParamFactory.ConvertParamsToUrl(this.SearchParams); //TODO: ensure double quotes are encoded. return(paramsUrl.ToString()); }
/// <summary> /// Gets the URL for the given cdrID. /// Returns the URL with the friendly-name if found, otherwise with the CDRID. /// </summary> public string GetSitemapUrl(DictionaryInfo info, string cdrId) { NciUrl url = new NciUrl(); url.SetUrl(_rootUrl); url.AppendPathSegment(info.DefinitionUrl); url.AppendPathSegment(GetFriendlyName(info, cdrId)); return(_rootUrl + url.ToString()); }
/// <summary> /// Gets the friendly name of the given CDRID, if it exists. /// Otherwise, returns the CDRID. /// </summary> public string GetSitemapUrl(string nciid) { NciUrl url = new NciUrl(); url.SetUrl(_rootUrl); url.AppendPathSegment(_config.DetailedViewPagePrettyUrl); url.QueryParameters.Add("id", nciid); return(_rootUrl + url.ToString()); }
public string GetCheckForUpdatesURL(string trialID, CTSSearchParams searchParams) { //Create a new url for the current details page. NciUrl url = new NciUrl(); url.SetUrl(_config.DetailedViewPagePrettyUrl); //Convert the current search parameters into a NciUrl NciUrl paramsUrl = CTSSearchParamFactory.ConvertParamsToUrl(searchParams); //Copy the params url.QueryParameters = paramsUrl.QueryParameters; url.QueryParameters.Add("id", trialID); return(url.ToString()); }
public string GetBackToResultsUrl() { //Create a new url for the current details page. NciUrl url = new NciUrl(); url.SetUrl(this.Config.ResultsPagePrettyUrl); //Convert the current search parameters into a NciUrl NciUrl paramsUrl = CTSSearchParamFactory.ConvertParamsToUrl(this.SearchParams); //Copy the params url.QueryParameters = paramsUrl.QueryParameters; url.QueryParameters.Add("pn", this.PageNum.ToString()); url.QueryParameters.Add("ni", this.ItemsPerPage.ToString()); return(url.ToString()); }
public void GetUrl_Test() { IPageAssemblyInstruction pageAssemblyInfo = null; pageAssemblyInfo = InitializeTestPageAssemblyInfo(); pageAssemblyInfo.AddUrlFilter("foo", (name, url) => { url.Clear(); url.UriStem = "/foo"; }); NciUrl expected = new NciUrl(); expected.UriStem = "/foo"; Assert.AreEqual(expected.ToString(), pageAssemblyInfo.GetUrl("foo").ToString()); }
public string GetShowAllUrl() { //Create a new url for the current details page. NciUrl url = new NciUrl(); url.SetUrl(this.Config.DetailedViewPagePrettyUrl); //Convert the current search parameters into a NciUrl NciUrl paramsUrl = CTSSearchParamFactory.ConvertParamsToUrl(this.SearchParams); //Copy the params url.QueryParameters = paramsUrl.QueryParameters; url.QueryParameters.Add("id", TrialID); url.QueryParameters.Add("pn", this.PageNum.ToString()); url.QueryParameters.Add("ni", this.ItemsPerPage.ToString()); url.QueryParameters.Add("all", "1"); return(url.ToString()); }
/// <summary> /// This method is called when no results are returned by the query. In this case the function checks that the current URL does not /// have the word notrials in it. If it is the case, the function will redirect the user to a page with the following URL: /// PRETTYURL/NOTRIALS?p1=a&p2=b /// </summary> protected override void OnEmptyResults() { if (this.IsNoTrials) { return; } NciUrl noTrialsUrl = new NciUrl(); noTrialsUrl.SetUrl(this.PrettyUrl + "/notrials"); //Parameters is always assumed to be greater than one string[] parameters = this.GetParametersForNoTrials(); for (int i = 0; i < parameters.Length; i++) { noTrialsUrl.QueryParameters.Add("p" + (i + 1), parameters[i]); } Response.Redirect(noTrialsUrl.ToString(), true); }
/// <summary> /// Gets URL for a Single Page of Results /// </summary> /// <param name="pageNum"></param> /// <returns></returns> public string GetPageUrl(int pageNum) { NciUrl url = this.PageInstruction.GetUrl("CurrentURL"); if (!url.QueryParameters.ContainsKey(PAGENUM_PARAM)) { url.QueryParameters.Add(PAGENUM_PARAM, pageNum.ToString()); } else { url.QueryParameters[PAGENUM_PARAM] = pageNum.ToString(); } //TODO: What about items per page? //TODO: Why are the filters not part of the URL already? //Add the filters back into the URL TrialListingQueryHelper.AddFilterParamsToUrl(url, HttpContext.Current.Request.QueryString); return(url.ToString()); }
// Sets the URL Filter for the canonical URL private void SetupUrlFilter(string name, NciUrl url) { url.SetUrl(url.ToString()); }
public void ProcessRequest(HttpContext context) { string command = (string)context.Request.QueryString[InformationRequestConstants.InformationRequestToken]; string notFoundMessage = ""; switch (command.ToLower()) { case "mobileurl": if (PageAssemblyContext.Current.PageAssemblyInstruction == null) { context.Response.Write(InformationRequestMessages.FileNotFound); } else { string[] alternateContentVersionsKeys = PageAssemblyContext.Current.PageAssemblyInstruction.AlternateContentVersionsKeys; if (Array.Find(alternateContentVersionsKeys, element => element.StartsWith("mobileurl", StringComparison.Ordinal)) == "mobileurl") { NciUrl mobileUrl = PageAssemblyContext.Current.PageAssemblyInstruction.GetUrl("mobileurl"); context.Response.Write(InformationRequestMessages.MobileUrlFound + " [" + mobileUrl.ToString() + "]"); } else { context.Response.Write(InformationRequestMessages.MobileUrlNotFound); } } break; case "canonicalurl": notFoundMessage = InformationRequestMessages.CanonicalUrlNotFound; if (PageAssemblyContext.Current.PageAssemblyInstruction != null) { string canonicalUrl = PageAssemblyContext.Current.PageAssemblyInstruction.GetUrl(PageAssemblyInstructionUrls.CanonicalUrl).ToString(); canonicalUrl = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + canonicalUrl; context.Response.Write(InformationRequestMessages.CanonicalUrlFound + " [" + canonicalUrl + "]"); } else { context.Response.Write(notFoundMessage); } break; default: context.Response.Write("Unknown Command:[" + command + "]"); break; } }
/// <summary> /// Method called to redirect old search URLs to the new search URL /// </summary> protected void RedirectToResultsList(string searchString, string contains, string first, string page) { NciUrl redirectURL = new NciUrl(); redirectURL.SetUrl(GetSearchUrl()); redirectURL.QueryParameters.Add("q", searchString); if (contains.Equals("true")) { redirectURL.QueryParameters.Add("contains", contains); } if (!string.IsNullOrEmpty(first)) { redirectURL.QueryParameters.Add("first", first); } if (!string.IsNullOrEmpty(page)) { redirectURL.QueryParameters.Add("page", page); } // Add redirect query parameter for analytics redirectURL.QueryParameters.Add("redirect", "true"); NCI.Web.CDE.Application.PermanentRedirector.DoPermanentRedirect(Response, redirectURL.ToString(), "Dictionary Friendly Name Redirect"); }
void OnBeginRequest(object sender, EventArgs e) { bool doRedirect = false; HttpContext context = ((HttpApplication)sender).Context; // if page assembly instructions are loaded if (PageAssemblyContext.Current.PageAssemblyInstruction != null) { // if mobile device and mobile url exist, redirect to it if ((DisplayDeviceDetector.DisplayDevice == DisplayDevices.BasicMobile) || (DisplayDeviceDetector.DisplayDevice == DisplayDevices.AdvancedMobile)) { string[] alternateContentVersionsKeys; alternateContentVersionsKeys = PageAssemblyContext.Current.PageAssemblyInstruction.AlternateContentVersionsKeys; if (Array.Find(alternateContentVersionsKeys, element => element.StartsWith("mobileurl", StringComparison.Ordinal)) == "mobileurl") { HttpCookie mobileRedirectCookie = context.Request.Cookies[_cookieName]; if (mobileRedirectCookie != null) { if (DateTime.Now.Ticks > (Convert.ToInt64(mobileRedirectCookie.Value) + (TimeSpan.TicksPerMinute * _cookieTimeoutMinutes))) { doRedirect = true; } } else { doRedirect = true; } if (doRedirect) { //drop a cookie so mobile redirect happens only once per session HttpCookie responseCookie = new HttpCookie(_cookieName, DateTime.Now.Ticks.ToString()); responseCookie.Expires = DateTime.MinValue; // Make this a session cookie responseCookie.Domain = _domain; context.Response.Cookies.Add(responseCookie); NciUrl mobileUrl = PageAssemblyContext.Current.PageAssemblyInstruction.GetUrl("mobileurl"); // We are adding query parameter to the mobile URL for the page to accommodate // the dictionary of cancer terms - so a link to a term dictionary definition // actually goes to the mobile dictionary definition, not just the dictionary home. string redirectUrl = InformationRequestConfig.MobileHost + mobileUrl.ToString() + context.Request.Url.Query; context.Response.Redirect(redirectUrl, true); } } } } }
/// <summary> /// Method called to redirect old view URLs to the new view URL /// </summary> protected void RedirectToDefinitionView(string id) { NciUrl redirectURL = new NciUrl(); string friendlyName = GetFriendlyName(id); if (!string.IsNullOrEmpty(friendlyName)) { redirectURL.SetUrl(GetDefinitionUrl() + friendlyName); } else { redirectURL.SetUrl(GetDefinitionUrl() + id); } // Add redirect query parameter for analytics redirectURL.QueryParameters.Add("redirect", "true"); NCI.Web.CDE.Application.PermanentRedirector.DoPermanentRedirect(Response, redirectURL.ToString(), "Dictionary Friendly Name Redirect"); }
/// <summary> /// Adds the specified link rel item to the head of the page. /// </summary> /// <param name="htmlHead">The html head of the current page.</param> /// <param name="htmlLinkRelType">The type ofrel item to add.</param> private void addLinkRelItem(HtmlHead htmlHead, HtmlLinkRelType htmlLinkRelType) { List <HtmlLink> linkList = new List <HtmlLink>(); if (htmlLinkRelType == HtmlLinkRelType.SchemaDcTerms) { HtmlLink hl = new HtmlLink(); hl.Attributes.Add("rel", "schema.dcterms"); hl.Href = "http://purl.org/dc/terms/"; linkList.Add(hl); } else if (htmlLinkRelType == HtmlLinkRelType.Alternate) { // only add any alternate links if some translation exists if (PageAssemblyContext.Current.PageAssemblyInstruction.TranslationKeys.Length > 0) { // retrieve the current language and hostname string pageLang = PageAssemblyContext.Current.PageAssemblyInstruction.GetField("Language"); bool hasShortLangCode = pageLang.Length <= 2; bool foundPageLang = false; foreach (string key in PageAssemblyContext.Current.PageAssemblyInstruction.TranslationKeys) { // use the two-character code for this language if the page's language is also two characters string translationLang = hasShortLangCode ? CultureInfo.GetCultureInfoByIetfLanguageTag(key).TwoLetterISOLanguageName : key; // track if the page's language has been found if (!foundPageLang && translationLang.Equals(pageLang, StringComparison.OrdinalIgnoreCase)) { foundPageLang = true; } // retrieve the translation URL NciUrl url = PageAssemblyContext.Current.PageAssemblyInstruction.GetTranslationUrl(key); // build and add htmllink to list HtmlLink hl = new HtmlLink(); hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + url.ToString(); hl.Attributes.Add("hreflang", translationLang); hl.Attributes.Add("rel", "alternate"); linkList.Add(hl); } if (!foundPageLang) { // add the canonical url as the rel link for the page's language string CanonicalUrl = PageAssemblyInstruction.GetUrl(PageAssemblyInstructionUrls.CanonicalUrl).ToString(); if (!string.IsNullOrEmpty(CanonicalUrl)) { // build and add htmllink HtmlLink hl = new HtmlLink(); hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + CanonicalUrl; hl.Attributes.Add("hreflang", pageLang); hl.Attributes.Add("rel", "alternate"); linkList.Add(hl); } } } } else if (htmlLinkRelType == HtmlLinkRelType.Next) { string nextUrl = PageAssemblyInstruction.GetUrl("RelNext").ToString(); if (!String.IsNullOrEmpty(nextUrl)) { HtmlLink hl = new HtmlLink(); hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + nextUrl; hl.Attributes.Add("rel", "next"); linkList.Add(hl); } } else if (htmlLinkRelType == HtmlLinkRelType.Prev) { string prevUrl = PageAssemblyInstruction.GetUrl("RelPrev").ToString(); if (!String.IsNullOrEmpty(prevUrl)) { HtmlLink hl = new HtmlLink(); hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + prevUrl; hl.Attributes.Add("rel", "prev"); linkList.Add(hl); } } foreach (HtmlLink hl in linkList) { htmlHead.Controls.Add(hl); } }
/// <summary> /// Method that builds HTML paging constructs based on class properties /// </summary> /// <returns>Paging HTML links</returns> public string RenderPager() { string result = ""; int startIndex = 0; int endIndex = 0; int pages = 0; //Get number of pages if (recordsPerPage > 0) { pages = recordCount / recordsPerPage; if (recordCount % recordsPerPage > 0) { pages += 1; } } foreach (KeyValuePair<string, string> pair in queryParams) { if(!pageBaseUrl.QueryParameters.ContainsKey(pair.Key)) { pageBaseUrl.QueryParameters.Add(pair.Key, pair.Value); } } if (pages > 1) { startIndex = currentPage - showPages > 0 ? currentPage - showPages : 1; endIndex = currentPage + showPages > pages ? pages : currentPage + showPages; string first = ""; string page = ""; string url = pageBaseUrl.ToString(); for (int i = startIndex; i <= endIndex; i++) { if (currentPage != i) { first = (((i - 1) * this.recordsPerPage) + 1).ToString(); page = i.ToString(); url = GetPagerUrl(pageBaseUrl, first, page); result += "<li><a href=\"" + url.ToString() + "\">" + i.ToString() + "</a></li>"; } else { result += "<li class='current'>" + i.ToString() + "</li>"; } } if (currentPage > 1) { first = (((currentPage - 2) * this.recordsPerPage) + 1).ToString(); page = (currentPage - 1).ToString(); url = GetPagerUrl(pageBaseUrl, first, page); result = "<li class='previous'><a href=\"" + url.ToString() + "\">Previous</a></li>" + result; } if (currentPage < pages) { first = (((currentPage) * this.recordsPerPage) + 1).ToString(); page = (currentPage + 1).ToString(); url = GetPagerUrl(pageBaseUrl, first, page); result += "<li class='next'><a href=\"" + url.ToString() + "\">Next</a></li>"; } result = "<div class='pagination'><ul class='no-bullets'>" + result + "</ul></div>"; } return result; }