本文整理汇总了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"]);
}
示例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"]);
}
示例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;
}
示例4: GetAccessTokenFromFragment
static string GetAccessTokenFromFragment(Uri uri)
{
HttpValueCollection httpValues = uri.ParseFragment();
string[] accessTokens = httpValues.GetValues("access_token");
return accessTokens.Length > 0 ? accessTokens[0] : null;
}
示例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);
}
示例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);
}