本文整理汇总了C#中System.UriBuilder.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# UriBuilder.StartsWith方法的具体用法?C# UriBuilder.StartsWith怎么用?C# UriBuilder.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.UriBuilder
的用法示例。
在下文中一共展示了UriBuilder.StartsWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPrefixUri
/// <summary>
/// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />.
/// </summary>
/// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param>
/// <param name="server">
/// The
/// <see cref="WebDavServer" /> that hosts the WebDAV server and holds the collection
/// of known prefixes.
/// </param>
/// <returns>
/// The most specific <see cref="Uri" /> for the given <paramref name="uri" />.
/// </returns>
/// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception>
/// <exception cref="WebDavInternalServerException">
/// <paramref name="uri" /> specifies a <see cref="Uri" /> that is not
/// known to the <paramref name="server" />.
/// </exception>
public static Uri GetPrefixUri(this Uri uri, WebDavServer server)
{
string url = uri.ToString();
string exactPrefix = server.Listener.Prefixes
.FirstOrDefault(item => url.StartsWith(item, StringComparison.OrdinalIgnoreCase));
if (!IsNullOrEmpty(exactPrefix))
{
return new Uri(exactPrefix);
}
string wildcardUrl = new UriBuilder(uri)
{
Host = "WebDAVSharpSpecialHostTag"
}
.ToString().Replace("WebDAVSharpSpecialHostTag", "*");
string wildcardPrefix = server.Listener.Prefixes
.FirstOrDefault(item => wildcardUrl.StartsWith(item, StringComparison.OrdinalIgnoreCase));
if (!IsNullOrEmpty(wildcardPrefix))
{
return new Uri(wildcardPrefix.Replace("://*", $"://{uri.Host}"));
}
throw new WebDavInternalServerException("Unable to find correct server root");
}
示例2: GetPrefixWithWildCard
private static Uri GetPrefixWithWildCard(Uri uri, WebDavServer server)
{
foreach (var wc in AllIpWildChards)
{
string wildcardUrl = new UriBuilder(uri) { Host = "WebDAVSharpSpecialHostTag" }
.ToString().Replace("WebDAVSharpSpecialHostTag", wc);
string wildcardPrefix = server.Listener.Prefixes
.FirstOrDefault(item => wildcardUrl.StartsWith(item, StringComparison.OrdinalIgnoreCase));
if (!String.IsNullOrEmpty(wildcardPrefix))
{
return new Uri(wildcardPrefix.Replace("://" + wc, string.Format("://{0}", uri.Host)));
}
}
return null;
}