protected void Page_Load(object sender, EventArgs e) { //提供在获取到OpenID时的转发页面,主要用于脚本间的跨域访问 Uri bridgeRelativeUrl = new Uri(this.ResolveUrl("OpenIDBridge.aspx"), UriKind.Relative); Uri bridgeUri = bridgeRelativeUrl.MakeAbsolute(this.Request.Url); QQAuthorizationCodeRequestParams requestParams = new QQAuthorizationCodeRequestParams(QQConnectionSettings.GetConfig().LoginCallback.ToString(), bridgeUri.ToString()); Response.Redirect(requestParams.ToUrl()); }
private static IDictionary<string, string> ParseQueryStringToDictionary(Uri uri) { if (uri == null) return EmptyUriDictionary; var dictionary = new Dictionary<string, string>(StringComparer.Ordinal); foreach (string url in uri.MakeAbsolute() .GetComponents(UriComponents.Query, UriFormat.SafeUnescaped) .Split("&".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { int length = url.IndexOf("=", StringComparison.Ordinal); if (length == -1) dictionary.Add(UrlDecode(url), string.Empty); else dictionary.Add(UrlDecode(url.Substring(0, length)), UrlDecode(url.Substring(length + 1))); } return dictionary; }
/// <summary> /// Gets the node Id by URL. /// </summary> /// <param name="url">The URL to get the XML node from.</param> /// <returns>Returns the node Id.</returns> /// <remarks> /// Thanks to Jonas Eriksson http://our.umbraco.org/member/4853 /// </remarks> public static int GetNodeIdByUrl(string url) { var uri = new Uri(url, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) uri = uri.MakeAbsolute(Umbraco.Web.UmbracoContext.Current.CleanedUmbracoUrl); uri = Umbraco.Web.UriUtility.UriToUmbraco(uri); var docreq = new Umbraco.Web.Routing.PublishedContentRequest(uri, Umbraco.Web.UmbracoContext.Current.RoutingContext); var builder = new Umbraco.Web.Routing.PublishedContentRequestBuilder(docreq); builder.LookupDomain(); builder.LookupDocument(); return docreq.HasNode ? docreq.DocumentId : uQuery.RootNodeId; }
public void MakeAbsolute(string input, string reference, string expected) { var source = new Uri(input, UriKind.Relative); var absolute = new Uri(reference); var output = source.MakeAbsolute(absolute); Assert.AreEqual(expected, output.ToString()); }
/// <summary> /// Gets the node Id by URL. /// </summary> /// <param name="url">The URL to get the XML node from.</param> /// <returns>Returns the node Id.</returns> /// <remarks> /// <para>Thanks to Jonas Eriksson http://our.umbraco.org/member/4853 </para> /// <para>Just runs lookups to find the document, does not follow internal redirects, 404 handlers, /// page access verification, wildcard domains -- nothing.</para> /// </remarks> public static int GetNodeIdByUrl(string url) { var uri = new Uri(url, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) uri = uri.MakeAbsolute(Umbraco.Web.UmbracoContext.Current.CleanedUmbracoUrl); uri = Umbraco.Web.UriUtility.UriToUmbraco(uri); var pcr = new Umbraco.Web.Routing.PublishedContentRequest(uri, Umbraco.Web.UmbracoContext.Current.RoutingContext); // partially prepare the request: do _not_ follow redirects, handle 404, nothing - just find a content pcr.Engine.FindDomain(); pcr.Engine.FindPublishedContent(); return pcr.HasPublishedContent ? pcr.PublishedContent.Id : uQuery.RootNodeId; }
/// <summary> /// 如果目标路径是相对地址,则转换为和baseUri相关的绝对地址 /// </summary> /// <param name="baseUri"></param> /// <returns></returns> public string MakeDestinationUrlAbsolute(Uri baseUri) { Uri destUri = new Uri(this.DestinationUrl, UriKind.RelativeOrAbsolute); if (destUri.IsAbsoluteUri == false) { baseUri.NullCheck("baseUri"); this.DestinationUrl = destUri.MakeAbsolute(baseUri).ToString(); } return this.DestinationUrl; }
public static bool MatchesUri(Uri navigationUri) { return navigationUri.MakeAbsolute().AbsolutePath == BaseNavigationUri.MakeAbsolute().AbsolutePath; }
public void MakeRootRelativeUriToToRelativePathTest() { Uri target = new Uri("/test.aspx", UriKind.RelativeOrAbsolute); Uri refUri = new Uri("/foo/bar.aspx", UriKind.RelativeOrAbsolute); Assert.AreEqual("/test.aspx", target.MakeAbsolute(refUri).ToString()); }
public void MakeRelativeUriWithBackDirToToAbsolutePathTest() { Uri target = new Uri("../test.aspx", UriKind.RelativeOrAbsolute); Uri refUri = new Uri("http://www.sina.com.cn/foo/bar.aspx"); Assert.AreEqual("http://www.sina.com.cn/test.aspx", target.MakeAbsolute(refUri).ToString()); }
public void MakeAbsoluteUriToAnthorAbsolutePathTest() { Uri target = new Uri("http://www.baidu.com/test.aspx"); Uri refUri = new Uri("http://www.sina.com.cn/foo/bar.aspx"); Assert.AreEqual("http://www.sina.com.cn/test.aspx", target.MakeAbsolute(refUri).ToString()); }