コード例 #1
0
        /// <summary>
        /// Get the provider authentication mode.
        /// </summary>
        /// <param name="url">The Uri instance.</param>
        /// <param name="providerName">The provider name</param>
        /// <param name="section">The config section group and section name.</param>
        /// <returns>The authentication mode.</returns>
        public static string GetProviderAuthentication(Uri url, string providerName, string section = "HttpServerGroup/HttpServerHosts")
        {
            string authName = null;

            try
            {
                // Get the http host collection elements.
                HttpHostElement[] httpHostElements = ElementReader.HttpHostElements(section);
                if (httpHostElements != null)
                {
                    // Get all provider hosts.
                    IEnumerable <HttpHostElement> hosts = httpHostElements.Where(u => u.HostAttribute.ToLower().Contains(providerName));

                    // If hosts have been found.
                    if (hosts.Count() > 0)
                    {
                        foreach (HttpHostElement item in hosts)
                        {
                            // If the current url and path are similar.
                            if (url.ToString().ToLower().Contains(item.PathAttribute.ToLower()))
                            {
                                // Get the authentication type.
                                authName = item.AuthenticationAttribute.ToString().ToLower();
                                break;
                            }
                        }
                    }

                    // Return the collection of hosts.
                    return(authName);
                }

                return(null);
            }
            catch (Exception ex)
            {
                // Log the error.
                LogHandler.WriteTypeMessage(
                    ex.Message,
                    MethodInfo.GetCurrentMethod(),
                    Nequeo.Net.Common.Helper.EventApplicationName);

                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the provider prefix path
        /// </summary>
        /// <param name="providerName">The provider name</param>
        /// <param name="section">The config section group and section name.</param>
        /// <returns>The collection of prefix paths.</returns>
        public string[] GetProviderPathPrefix(string providerName, string section = "HttpServerGroup/HttpServerHosts")
        {
            List <string> prefixPaths = new List <string>();

            try
            {
                // Get the host collection elements.
                HttpHostElement[] httpHostElements = ElementReader.HttpHostElements(section);
                if (httpHostElements != null)
                {
                    // Get all provider hosts.
                    IEnumerable <HttpHostElement> hosts = httpHostElements.Where(u => u.HostAttribute.ToLower().Contains(providerName.ToLower()));

                    // If hosts have been found. Add each prefix path.
                    if (hosts.Count() > 0)
                    {
                        foreach (HttpHostElement item in hosts)
                        {
                            prefixPaths.Add(item.PathAttribute);
                        }
                    }

                    // Return the collection of hosts.
                    return(prefixPaths.ToArray());
                }

                return(null);
            }
            catch (Exception ex)
            {
                // Log the error.
                LogHandler.WriteTypeMessage(
                    ex.Message,
                    MethodInfo.GetCurrentMethod(),
                    Nequeo.Net.Common.Helper.EventApplicationName);

                return(null);
            }
        }