当前位置: 首页>>代码示例>>C#>>正文


C# UriBuilder.StartsWith方法代码示例

本文整理汇总了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");
        }
开发者ID:Winterleaf,项目名称:WebDAVSharp.Server,代码行数:45,代码来源:WebDAVExtensions.cs

示例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;
        }
开发者ID:ProximoSrl,项目名称:WebDAVSharp.Server,代码行数:16,代码来源:WebDAVExtensions.cs


注:本文中的System.UriBuilder.StartsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。