public static UrlString BuildUrl(PageUrlOptions options) { Verify.ArgumentNotNull(options, "options"); Verify.ArgumentCondition(options.UrlType != UrlType.Undefined, "options", "Url type is undefined"); return(BuildUrl(options.UrlType, options)); }
public static bool TryParseFriendlyUrl(string relativeUrl, out PageUrlOptions urlOptions) { if (IsAdminPath(relativeUrl)) { urlOptions = null; return(false); } string path; CultureInfo cultureInfo = PageUrl.GetCultureInfo(relativeUrl, out path); if (cultureInfo == null) { urlOptions = null; return(false); } string loweredRelativeUrl = relativeUrl.ToLower(CultureInfo.InvariantCulture); // Getting the site map IEnumerable <XElement> siteMap; DataScopeIdentifier dataScope = DataScopeIdentifier.GetDefault(); using (new DataScope(dataScope, cultureInfo)) { siteMap = PageStructureInfo.GetSiteMap(); } XAttribute matchingAttributeNode = siteMap.DescendantsAndSelf() .Attributes("FriendlyUrl") .FirstOrDefault(f => string.Equals(f.Value, loweredRelativeUrl, StringComparison.OrdinalIgnoreCase)); if (matchingAttributeNode == null) { urlOptions = null; return(false); } XElement pageNode = matchingAttributeNode.Parent; XAttribute pageIdAttr = pageNode.Attributes("Id").FirstOrDefault(); Verify.IsNotNull(pageIdAttr, "Failed to get 'Id' attribute from the site map"); Guid pageId = new Guid(pageIdAttr.Value); urlOptions = new PageUrlOptions(dataScope.Name, cultureInfo, pageId, UrlType.Friendly); return(true); }
public static UrlString BuildUrl(UrlType urlType, PageUrlOptions options) { Verify.ArgumentNotNull(options, "options"); Verify.ArgumentCondition(urlType != UrlType.Undefined, "urlType", "Url type is undefined"); if (urlType == UrlType.Public) { var lookupTable = PageStructureInfo.GetIdToUrlLookup(options.DataScopeIdentifierName, options.Locale); if (!lookupTable.ContainsKey(options.PageId)) { return(null); } var publicUrl = new UrlString(lookupTable[options.PageId]); if (options.DataScopeIdentifierName != DataScopeIdentifier.GetDefault().Name) { publicUrl["dataScope"] = options.DataScopeIdentifierName; } return(publicUrl); } if (urlType == UrlType.Internal) { string basePath = UrlUtils.ResolvePublicUrl("Renderers/Page.aspx"); var result = new UrlString(basePath); result["pageId"] = options.PageId.ToString(); result["cultureInfo"] = options.Locale.ToString(); result["dataScope"] = options.DataScopeIdentifierName; return(result); } throw new NotImplementedException("BuildUrl function supports only 'Public' and 'Unternal' urls."); }
public static bool TryParseFriendlyUrl(string relativeUrl, out PageUrlOptions urlOptions) { if (IsAdminPath(relativeUrl)) { urlOptions = null; return false; } string path; CultureInfo cultureInfo = PageUrl.GetCultureInfo(relativeUrl, out path); if (cultureInfo == null) { urlOptions = null; return false; } string loweredRelativeUrl = relativeUrl.ToLower(CultureInfo.InvariantCulture); // Getting the site map IEnumerable<XElement> siteMap; DataScopeIdentifier dataScope = DataScopeIdentifier.GetDefault(); using (new DataScope(dataScope, cultureInfo)) { siteMap = PageStructureInfo.GetSiteMap(); } XAttribute matchingAttributeNode = siteMap.DescendantsAndSelf() .Attributes("FriendlyUrl") .FirstOrDefault(f => string.Equals(f.Value, loweredRelativeUrl, StringComparison.OrdinalIgnoreCase)); if(matchingAttributeNode == null) { urlOptions = null; return false; } XElement pageNode = matchingAttributeNode.Parent; XAttribute pageIdAttr = pageNode.Attributes("Id").FirstOrDefault(); Verify.IsNotNull(pageIdAttr, "Failed to get 'Id' attribute from the site map"); Guid pageId = new Guid(pageIdAttr.Value); urlOptions = new PageUrlOptions(dataScope.Name, cultureInfo, pageId, UrlType.Friendly); return true; }
public static UrlString BuildUrl(UrlType urlType, PageUrlOptions options) { Verify.ArgumentNotNull(options, "options"); Verify.ArgumentCondition(urlType != UrlType.Undefined, "urlType", "Url type is undefined"); if (urlType == UrlType.Public) { var lookupTable = PageStructureInfo.GetIdToUrlLookup(options.DataScopeIdentifierName, options.Locale); if (!lookupTable.ContainsKey(options.PageId)) { return null; } var publicUrl = new UrlString(lookupTable[options.PageId]); if(options.DataScopeIdentifierName != DataScopeIdentifier.GetDefault().Name) { publicUrl["dataScope"] = options.DataScopeIdentifierName; } return publicUrl; } if(urlType == UrlType.Internal) { string basePath = UrlUtils.ResolvePublicUrl("Renderers/Page.aspx"); var result = new UrlString(basePath); result["pageId"] = options.PageId.ToString(); result["cultureInfo"] = options.Locale.ToString(); result["dataScope"] = options.DataScopeIdentifierName; return result; } throw new NotImplementedException("BuildUrl function supports only 'Public' and 'Unternal' urls."); }
public static UrlString BuildUrl(PageUrlOptions options) { Verify.ArgumentNotNull(options, "options"); Verify.ArgumentCondition(options.UrlType != UrlType.Undefined, "options", "Url type is undefined"); return BuildUrl(options.UrlType, options); }