當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。