System.UriBuilder.ToString C# (CSharp) Method

ToString() public method

public ToString ( ) : string
return string
        public override string ToString() {

            if (m_username.Length == 0 && m_password.Length > 0) {
                throw new UriFormatException(SR.GetString(SR.net_uri_BadUserPassword));
            }

            if (m_scheme.Length != 0)
            {
                UriParser syntax = UriParser.GetSyntax(m_scheme);
                if (syntax != null)
                    m_schemeDelimiter = syntax.InFact(UriSyntaxFlags.MustHaveAuthority) ||
                                        (m_host.Length != 0 && syntax.NotAny(UriSyntaxFlags.MailToLikeUri) && syntax.InFact(UriSyntaxFlags.OptionalAuthority ))
                            ? Uri.SchemeDelimiter
                            : ":";
                else
                    m_schemeDelimiter = m_host.Length != 0? Uri.SchemeDelimiter: ":";
            }

            string result = m_scheme.Length != 0? (m_scheme + m_schemeDelimiter): string.Empty;
            return result
                    + m_username
                    + ((m_password.Length > 0) ? (":" + m_password) : String.Empty)
                    + ((m_username.Length > 0) ? "@" : String.Empty)
                    + m_host
                    + (((m_port != -1) && (m_host.Length > 0)) ? (":" + m_port) : String.Empty)
                    + (((m_host.Length > 0) && (m_path.Length != 0) && (m_path[0] != '/')) ? "/" : String.Empty) + m_path
                    + m_query
                    + m_fragment;
        }
    }

Usage Example

        public void DirectUserToServiceProvider()
        {
            UriBuilder ub = new UriBuilder(provider.UserLoginEndpoint);
            try
            {
                QueryParameters oauthParams = new QueryParameters();
                oauthParams.Add("client_id", provider.Consumerkey);
                oauthParams.Add("redirect_uri", connectionToken.ProviderCallbackUrl);
                oauthParams.Add("response_type", "code");
                oauthParams.Add("scope", provider.GetScope());
                //ub.SetQueryparameter("client_id", provider.Consumerkey);
                //ub.SetQueryparameter("redirect_uri", connectionToken.ProviderCallbackUrl);
                //ub.SetQueryparameter("response_type", "code");
                //ub.SetQueryparameter("scope", provider.GetScope());

                BeforeDirectingUserToServiceProvider(oauthParams);
                logger.Debug("Redirecting user for login to " + ub.ToString() + "?" + oauthParams.ToEncodedString());
                SocialAuthUser.Redirect(ub.ToString() + "?" + oauthParams.ToEncodedString());
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.UserLoginRedirectionError(ub.ToString()), ex);
                throw new OAuthException(ErrorMessages.UserLoginRedirectionError(ub.ToString()), ex);
            }
        }
All Usage Examples Of System.UriBuilder::ToString