當前位置: 首頁>>代碼示例>>C#>>正文


C# Uri.ParseFragment方法代碼示例

本文整理匯總了C#中System.Uri.ParseFragment方法的典型用法代碼示例。如果您正苦於以下問題:C# Uri.ParseFragment方法的具體用法?C# Uri.ParseFragment怎麽用?C# Uri.ParseFragment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Uri的用法示例。


在下文中一共展示了Uri.ParseFragment方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ParseFragment_QueryStringWithFragmentTest

 public void ParseFragment_QueryStringWithFragmentTest()
 {
     var uri = new Uri("http://foo.com/bar?c=something#a=123&b=whatever");
     var parameters = uri.ParseFragment();
     Assert.AreEqual(2, parameters.Count);
     Assert.AreEqual("123", parameters["a"]);
     Assert.AreEqual("whatever", parameters["b"]);
 }
開發者ID:FacticiusVir,項目名稱:ps-rich-client,代碼行數:8,代碼來源:ExtensionMethodTests.cs

示例2: ParseFragmentTest

 public void ParseFragmentTest()
 {
     Uri uri = new Uri("http://foo.com/bar#a=123&b=whatever");
     Dictionary<string, string> parameters = uri.ParseFragment();
     Assert.AreEqual(2, parameters.Count);
     Assert.AreEqual("123", parameters["a"]);
     Assert.AreEqual("whatever", parameters["b"]);
 }
開發者ID:FacticiusVir,項目名稱:ps-rich-client,代碼行數:8,代碼來源:ExtensionMethodTests.cs

示例3: Parse

        public static MicrosoftAccessInfo Parse(Uri uri)
        {
            Dictionary<string, string> parameters = uri.ParseFragment();
            string accessToken, expiresIn;
            int expirationInSeconds;
            MicrosoftAccessInfo accessInfo = null;
            if (parameters.TryGetValue(AccessTokenParameter, out accessToken) &&
                parameters.TryGetValue(ExpiresInParameter, out expiresIn) &&
                Int32.TryParse(expiresIn, out expirationInSeconds))
            {
                string refreshToken;
                parameters.TryGetValue(RefreshTokenParameter, out refreshToken);
                accessInfo = new MicrosoftAccessInfo(accessToken, refreshToken, TimeSpan.FromSeconds(expirationInSeconds));
            }

            return accessInfo;
        }
開發者ID:FacticiusVir,項目名稱:ps-rich-client,代碼行數:17,代碼來源:MicrosoftAccessInfo.cs

示例4: GetAccessTokenFromFragment

 static string GetAccessTokenFromFragment(Uri uri)
 {
     HttpValueCollection httpValues = uri.ParseFragment();
     string[] accessTokens = httpValues.GetValues("access_token");
     return accessTokens.Length > 0 ? accessTokens[0] : null;
 }
開發者ID:andreychizhov,項目名稱:microsoft-aspnet-samples,代碼行數:6,代碼來源:ExternalLoginManager.cs

示例5: ExtractAccessTokenFromUri

        /// <summary>
        /// Extracts the access token from the specified <see cref="Uri"/>.
        /// </summary>
        /// <param name="redirectUri">The redirect <see cref="Uri"/> that contains an access token.</param>
        /// <returns>
        /// The <see cref="OAuthTokens"/> object which contains both the <see cref="OAuthTokens.AccessToken"/> and 
        /// <see cref="OAuthTokens.AccessTokenExpiresInSeconds"/> properties.
        /// </returns>
        public OAuthTokens ExtractAccessTokenFromUri(Uri redirectUri)
        {            
            var fragmentParts = redirectUri.ParseFragment();

            if (!fragmentParts.ContainsKey("access_token"))
            {
                throw new InvalidOperationException(ErrorMessages.UriDoesntContainAccessToken);
            }

            if (!fragmentParts.ContainsKey("expires_in"))
            {
                throw new InvalidOperationException(ErrorMessages.UriDoesntContainAccessToken);
            }

            return OAuthTokens = new OAuthTokens(fragmentParts["access_token"], int.Parse(fragmentParts["expires_in"]), null);            
        }
開發者ID:moinahmed,項目名稱:BingAds-dotNet-SDK,代碼行數:24,代碼來源:OAuthDesktopMobileImplicitGrant.cs

示例6: ParseFragment_PlainFragmentTest

 public void ParseFragment_PlainFragmentTest()
 {
     var uri = new Uri("http://foo.com/bar#random");
     var parameters = uri.ParseFragment();
     Assert.AreEqual(0, parameters.Count);
 }
開發者ID:FacticiusVir,項目名稱:ps-rich-client,代碼行數:6,代碼來源:ExtensionMethodTests.cs


注:本文中的System.Uri.ParseFragment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。