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


C# UriBuilder.ToString方法代码示例

本文整理汇总了C#中System.UriBuilder.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# UriBuilder.ToString方法的具体用法?C# UriBuilder.ToString怎么用?C# UriBuilder.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.UriBuilder的用法示例。


在下文中一共展示了UriBuilder.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SubmitScore

		public void SubmitScore()
		{
			var userId = User.Identity.GetUserId();

			var score = scoreRepo.Find(userId);
			if (score == null)
				throw new Exception("Score for user '" + userId + "' not found");

			var ltiRequest = ltiRequestsRepo.Find(userId);
			if (ltiRequest == null)
				throw new Exception("LtiRequest for user '" + userId + "' not found");

			var consumerSecret = consumersRepo.Find(ltiRequest.ConsumerKey).Secret;


			// TODO: fix outcome address in local edx (no localhost and no https)
			var uri = new UriBuilder(ltiRequest.LisOutcomeServiceUrl);
			if (uri.Host == "localhost")
			{
				uri.Host = "192.168.33.10";
				uri.Port = 80;
				uri.Scheme = "http";
			}

			var result = OutcomesClient.PostScore(uri.ToString(), ltiRequest.ConsumerKey, consumerSecret,
				ltiRequest.LisResultSourcedId, score.Value/100.0);

			if (!result.IsValid)
				throw new Exception(uri.ToString() + "\r\n\r\n" + result.Message);
		}
开发者ID:Tinkturianec,项目名称:uLearn.Lti,代码行数:30,代码来源:HomeController.cs

示例2: DirectUserToServiceProvider

        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);
            }
        }
开发者ID:ranade80,项目名称:Authorization-Samples,代码行数:25,代码来源:OAuth2_0Server.cs

示例3: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            XmlDocument wsResponseXmlDoc = new XmlDocument();

            //http://api.worldweatheronline.com/free/v2/weather.ashx?q=china&format=xml&num_of_days=5&key=x35ahuadjhmdp5rb75ddw2ha
            //id=jipx(spacetime0)
            UriBuilder url = new UriBuilder();
            url.Scheme = "http";// Same as "http://"

            String key = System.Configuration.ConfigurationManager.AppSettings["key"];

            url.Host = "api.worldweatheronline.com";
            url.Path = "free/v1/weather.ashx";
            url.Query = "q=china&format=xml&num_of_days=5&key=" + key;

            String cacheurl = File.ReadAllText("D:/New folder/Visual Studio 2015/Projects/WebApplication1/WebApplication1/cache.txt");

            if (String.Compare(cacheurl, url.ToString()) == 0)
            {
                wsResponseXmlDoc = new XmlDocument();
                wsResponseXmlDoc.Load("D:/New folder/Visual Studio 2015/Projects/WebApplication1/WebApplication1/WeatherServiceCache.xml");

                //display the XML response 
                String xmlString = wsResponseXmlDoc.InnerXml;
                Response.ContentType = "text/xml";
                Response.Write(xmlString);
            }
            else
            {

                //Make a HTTP request to the global weather web service
                wsResponseXmlDoc = MakeRequest(url.ToString());

                int count = 0;

                while (count != 3 && wsResponseXmlDoc == null)
                {
                    wsResponseXmlDoc = MakeRequest(url.ToString());
                    count++;
                }

                if (wsResponseXmlDoc != null)
                {
                    //display the XML response 
                    String xmlString = wsResponseXmlDoc.InnerXml;
                    Response.ContentType = "text/xml";
                    Response.Write(xmlString);

                    String folder = "D:/New folder/Visual Studio 2015/Projects/WebApplication1/WebApplication1";
                    File.WriteAllText(folder + @"/cache.txt", url.ToString());
                    wsResponseXmlDoc.Save("D:/New folder/Visual Studio 2015/Projects/WebApplication1/WebApplication1/WeatherServiceCache.xml");
                }
                else
                {
                    Response.ContentType = "text/html";
                    Response.Write("<h2> error  accessing web service </h2>");

                }
            }
        }
开发者ID:tykoh764,项目名称:p1431012,代码行数:60,代码来源:WeatherService.aspx.cs

示例4: GetEndpoints

        public static void GetEndpoints(this Session session, string address, bool useInt, bool useExt, string internalPath, string externalPath,
            out string internalURI, out string externalURI)
        {
            internalURI = String.Empty;
            externalURI = String.Empty;

            if (!useExt && !useInt)
            {
                session.SendError("No endpoints were set.");
            }
            else
            {
                try
                {
                    var uriBuilder = new UriBuilder(address);
                    if (useExt)
                    {
                        uriBuilder.Path = externalPath;
                        externalURI = uriBuilder.ToString();
                    }

                    if (useInt)
                    {
                        uriBuilder.Path = internalPath;
                        internalURI = uriBuilder.ToString();
                    }
                }
                catch
                {
                    session.SendError("The web service address was invalid.");
                }
            }
        }
开发者ID:dspiegs,项目名称:DSpiegsUtil,代码行数:33,代码来源:CustomActionHelper.cs

示例5: WebSearchCommand

        public WebSearchCommand(string searchKeyword, string defaultUri, string searchUri)
        {
            _searchKeyword = searchKeyword;
            _defaultUri = defaultUri;
            _searchUri = searchUri;

            string rootUri = (new Uri(defaultUri)).GetLeftPart(UriPartial.Authority);
            UriBuilder faviconUri = new UriBuilder(rootUri);
            faviconUri.Path = "/apple-touch-icon.png";

            _icon = GetWebIcon(faviconUri.ToString());
            if (_icon == null)
            {
                faviconUri.Path = "/favicon.ico";
                _icon = GetWebIcon(faviconUri.ToString());
            }

            if (_icon != null)
            {
                // TODO: hack
                try
                {
                    _icon.MakeTransparent();
                }
                catch (InvalidOperationException)
                {
                    // Actual icons cannot be made transparent (they already are)
                }
            }
        }
开发者ID:schmich,项目名称:ephemeral,代码行数:30,代码来源:WebSearchCommand.cs

示例6: ToBcd_Test

        public void ToBcd_Test()
        {
            UriBuilder uri = new UriBuilder("http://a/b/c");
            uri = uri.AddQuery("name", "z");

            Assert.AreEqual("http://a:80/b/c?name=z", uri.ToString());
            uri = uri.AddQuery("age", "12");
            Assert.AreEqual("http://a:80/b/c?name=z&age=12", uri.ToString());
        }
开发者ID:yangwen27,项目名称:moonlit,代码行数:9,代码来源:UriBuilderExtensionsTests.cs

示例7: PerformCommand

        public override int PerformCommand( ICommandArgument[] Arguments, out ICommandResult CommandResult )
        {
            CommandResult = null;

            System.UriBuilder searchBinding = new System.UriBuilder();

            searchBinding.Scheme = "http";
            searchBinding.Host = searchServer;
            searchBinding.Path = searchRoot;

            string searchQuery = searchQueryPrefix;

            for ( int currentArgument = 1; currentArgument < Arguments.Length; currentArgument++ )
            {
                if ( currentArgument > 1 )
                {
                    searchQuery += "%20";
                }

                searchQuery += Arguments[currentArgument].GetArgument();
            }

            searchBinding.Query = searchQuery;

            _Terminal.WriteTo(
                new StringBuilder( searchBinding.ToString() + "\n\n" ),
                ConsoleProcessRedirection.OutputType.StandardOutput );

            PageCommand pageRetriever = new PageCommand(
                _CommandProcessor,
                new NullTerminal() );

            ICommandArgument[] showArguments = new ICommandArgument[2];

            showArguments[0] = Arguments[0];
            showArguments[1] = new CommandArgument( searchBinding.ToString() );

            pageRetriever.PerformCommand(
                showArguments,
                out CommandResult );

            string resultString = ( (StringBuilder) CommandResult.GetArgument() ).ToString();

            string[] links = FindLinks( resultString );

            foreach ( string link in links )
            {
                _Terminal.WriteTo(
                    new StringBuilder( link + "\n\n" ),
                    ConsoleProcessRedirection.OutputType.StandardOutput );
            }

            return 0;
        }
开发者ID:adamedx,项目名称:shango,代码行数:54,代码来源:MsnCommand.cs

示例8: SetQueryTest

        public void SetQueryTest()
        {
            UriBuilder uriBuilder = new UriBuilder("http://", "mccoysoftware.uk");

            // Note the absence of a '?' character
            uriBuilder.SetQuery("Title=Mr&FirstName=Arthur&Surname=Dent");
            Assert.AreEqual("http://mccoysoftware.uk/?Title=Mr&FirstName=Arthur&Surname=Dent", uriBuilder.ToString());

            // Now WITH a '?'
            uriBuilder.SetQuery("?Title=Mr&FirstName=Ford&Surname=Prefect");
            Assert.AreEqual("http://mccoysoftware.uk/?Title=Mr&FirstName=Ford&Surname=Prefect", uriBuilder.ToString());
        }
开发者ID:gitter-badger,项目名称:UrlUtilities,代码行数:12,代码来源:ExtensionTests.cs

示例9: RemoveQueryParamTest

        public void RemoveQueryParamTest()
        {
            UriBuilder uriBuilder = new UriBuilder("http://", "mccoysoftware.uk");
            uriBuilder.Query = "Title=Mr&FirstName=Arthur&Surname=Dent";

            // First assert we know the starting string
            Assert.AreEqual("http://mccoysoftware.uk/?Title=Mr&FirstName=Arthur&Surname=Dent", uriBuilder.ToString());

            // Now assert we can remove a parameter (from the middle)
            uriBuilder.RemoveQueryParam("FirstName");
            Assert.AreEqual("http://mccoysoftware.uk/?Title=Mr&Surname=Dent", uriBuilder.ToString());
        }
开发者ID:gitter-badger,项目名称:UrlUtilities,代码行数:12,代码来源:ExtensionTests.cs

示例10: SetQueryParamTest

        public void SetQueryParamTest()
        {
            UriBuilder uriBuilder = new UriBuilder("http://", "mccoysoftware.uk");
            uriBuilder.SetQueryParam("FirstName", "Arthur");
            Assert.AreEqual("http://mccoysoftware.uk/?FirstName=Arthur", uriBuilder.ToString());
            uriBuilder.SetQueryParam("Surname", "Dent");
            Assert.AreEqual("http://mccoysoftware.uk/?FirstName=Arthur&Surname=Dent", uriBuilder.ToString());

            // It should be possible to overwrite the values set above
            uriBuilder.SetQueryParam("FirstName", "Ford");
            uriBuilder.SetQueryParam("Surname", "Prefect");
            Assert.AreEqual("http://mccoysoftware.uk/?FirstName=Ford&Surname=Prefect", uriBuilder.ToString());
        }
开发者ID:gitter-badger,项目名称:UrlUtilities,代码行数:13,代码来源:ExtensionTests.cs

示例11: GetActionUrl

        protected override string GetActionUrl(UrlHelper urlHelper, object routeValues)
        {
            var urlString = urlHelper.RouteUrl(this.RouteName, routeValues, urlHelper.RequestContext.HttpContext.Request.Url.Scheme);
            var urlBuilder = new UriBuilder(urlString);

            if (!urlBuilder.Host.Contains(".")) // this should be overridable in future, but not now
                return urlBuilder.ToString();

            Interlocked.Increment(ref currentIndex);
            Interlocked.CompareExchange(ref currentIndex, 1, 6);

            urlBuilder.Host = string.Format(subdomainPattern, currentIndex) + "." + urlBuilder.Host;
            return urlBuilder.ToString();
        }
开发者ID:ashmind,项目名称:gallery,代码行数:14,代码来源:SubdomainImageRequestStrategy.cs

示例12: Gmusicbrowser

 public Gmusicbrowser(string hostname, UInt16 port)
 {
     var uri = new UriBuilder ();
     Hostname = hostname;
     Port = port;
     uri.Host = hostname;
     uri.Port = port;
     uri.Scheme = "http";
     try {
         new Uri (uri.ToString ()); // throw an exception if the URI is invalid
     } catch {
         throw new FormatException("Invalid hostname or port");
     }
     gmbClient = new RestClient (uri.ToString());
 }
开发者ID:orospakr,项目名称:gmusicbrowser-remote,代码行数:15,代码来源:Gmusicbrowser.cs

示例13: ReplacingQueryStringParameter

        public static string ReplacingQueryStringParameter(string currentPageUrl, string ParameterToReplace, string NewValue)
        {
            var myquery = AnalyseQueryString(currentPageUrl);

            myquery[ParameterToReplace] = NewValue;

            var resultQuery = new StringBuilder();
            bool isFirst = true;

            foreach (KeyValuePair<string, string> pair in myquery)
            {
                if (!isFirst)
                {
                    resultQuery.Append("&");
                }

                resultQuery.Append(pair.Key);
                resultQuery.Append("=");
                resultQuery.Append(pair.Value);

                isFirst = false;
            }

            var Builder = new UriBuilder(currentPageUrl)
            {
                Query = resultQuery.ToString()
            };

            return Builder.ToString();
        }
开发者ID:JeanPhilippeKernel,项目名称:JeanPhilippe_Youtube-dl,代码行数:30,代码来源:HttpRequestHelper.cs

示例14: ModifyResponseToRedirectToSessionAwareUrl

    public void ModifyResponseToRedirectToSessionAwareUrl(NancyContext context, SessionIdentificationData sessionIdentificationData, string parameterName) {
      if (context == null) throw new ArgumentNullException("context");
      if (sessionIdentificationData == null) throw new ArgumentNullException("sessionIdentificationData");
      if (string.IsNullOrWhiteSpace(parameterName)) throw new ArgumentNullException("parameterName");
      if (context.Request == null) throw new ArgumentException("The specified context does not contain a request", "context");
      if (context.Response == null) throw new ArgumentException("The specified context does not contain a response", "context");

      var originalUri = (Uri) context.Request.Url;
      var uriBuilder = new UriBuilder(originalUri);
      var queryParameters = HttpUtility.ParseQueryString(uriBuilder.Query);
      queryParameters.Set(parameterName, sessionIdentificationData.ToString());

      var newQueryString = string.Empty;
      if (queryParameters.Count > 0) {
        var newQueryBuilder = new StringBuilder();
        foreach (var paramName in queryParameters.AllKeys) {
          newQueryBuilder.Append(string.Format("{0}={1}&", paramName, HttpUtility.UrlEncode(queryParameters[paramName])));
        }
        newQueryString = newQueryBuilder.ToString().TrimEnd('&');
      }
      uriBuilder.Query = newQueryString;
      var redirectUrl = uriBuilder.ToString();

      context.Response.StatusCode = HttpStatusCode.Found;
      context.Response.Headers["Location"] = redirectUrl;
    }
开发者ID:DavidLievrouw,项目名称:Nancy.Session.InProc,代码行数:26,代码来源:ResponseManipulatorForSession.cs

示例15: ScrapePage

        public List<ArticleInfo> ScrapePage(Section section, int page)
        {
            var builder = new UriBuilder(section.Host);
            builder.Path += section.RelativeUrl;
            var url = builder.ToString().AddQueryParameterToUrl("page", page);

            var docNode = Utilities.DownloadPage(url);
            var articleDivs = docNode.SelectNodes("//div[@class='category-headline-item']");

            var result = new List<ArticleInfo>();

            foreach (var articleDiv in articleDivs)
            {
                try
                {
                    result.Add(ParseArticleInfoDiv(articleDiv));
                }
                catch (CommonParsingException e)
                {
                }
                catch (Exception e)
                {
                    e.Data["articleDiv"] = articleDiv.OuterHtml;
                    _log.Error("An error occurred while parsing article info div.", e);
                }
            }

            return result;
        }
开发者ID:jonas-paul,项目名称:portal-scrape,代码行数:29,代码来源:DelfiArticleInfoScraper.cs


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