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


C# QueryString类代码示例

本文整理汇总了C#中QueryString的典型用法代码示例。如果您正苦于以下问题:C# QueryString类的具体用法?C# QueryString怎么用?C# QueryString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: BuildAbsolute

        /// <summary>
        /// Combines the given URI components into a string that is properly encoded for use in HTTP headers.
        /// Note that unicode in the HostString will be encoded as punycode.
        /// </summary>
        /// <param name="scheme">http, https, etc.</param>
        /// <param name="host">The host portion of the uri normally included in the Host header. This may include the port.</param>
        /// <param name="pathBase">The first portion of the request path associated with application root.</param>
        /// <param name="path">The portion of the request path that identifies the requested resource.</param>
        /// <param name="query">The query, if any.</param>
        /// <param name="fragment">The fragment, if any.</param>
        /// <returns></returns>
        public static string BuildAbsolute(
            string scheme,
            HostString host,
            PathString pathBase = new PathString(),
            PathString path = new PathString(),
            QueryString query = new QueryString(),
            FragmentString fragment = new FragmentString())
        {
            var combinedPath = (pathBase.HasValue || path.HasValue) ? (pathBase + path).ToString() : "/";

            var encodedHost = host.ToString();
            var encodedQuery = query.ToString();
            var encodedFragment = fragment.ToString();

            // PERF: Calculate string length to allocate correct buffer size for StringBuilder.
            var length = scheme.Length + SchemeDelimiter.Length + encodedHost.Length
                + combinedPath.Length + encodedQuery.Length + encodedFragment.Length;

            return new StringBuilder(length)
                .Append(scheme)
                .Append(SchemeDelimiter)
                .Append(encodedHost)
                .Append(combinedPath)
                .Append(encodedQuery)
                .Append(encodedFragment)
                .ToString();
        }
开发者ID:tuespetre,项目名称:HttpAbstractions,代码行数:38,代码来源:UriHelper.cs

示例2: Execute

    public virtual IPromise<IHttpResponse> Execute(string method, string baseUrl, QueryString queryString, System.Net.ICredentials credentials, bool async, Action<IHttpRequest> configure)
    {
      var uri = baseUrl + (queryString == null ? "" : queryString.ToString());

      var req = (HttpWebRequest)System.Net.WebRequest.Create(uri);
      req.AllowAutoRedirect = this.AllowAutoRedirect;
      if (this.AutomaticDecompression) req.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
      if (this.StoreCookies) req.CookieContainer = _cookieContainer;
      req.Method = method;
      req.ReadWriteTimeout = 300000;
      req.Timeout = DefaultTimeout;
      if (method == "POST")
      {
        req.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
      }
      req.Credentials = credentials;
      var result = new WebRequest(req, this.Compression);
      if (configure != null) configure.Invoke(result);

      var st = Stopwatch.StartNew();
      return result.Execute(async).Convert(r => {
        if (r.Core.Cookies.Count > 0) SetCookies(r.Core.Cookies);
        return (IHttpResponse)r;
      }).Always(() => {
        st.Stop();
        _httpTracing.TraceData(TraceEventType.Verbose, 0, st.ElapsedMilliseconds);
      });
    }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:28,代码来源:DefaultHttpService.cs

示例3: Login

        public ActionResult Login(string returnUrl)
        {
            if (!User.Identity.IsAuthenticated)
            {
                // User is not authenticated.
                // WSFederationAuthenticationModule is configured to kick in
                // when in EndRequest a request indicates "unauthorized access".
                // Therefore, the following call will start the login process,
                // and after completion, will come back to this address.
                return new HttpUnauthorizedResult();
            }

            // The user successfully authenticated.

            string nameIdentifier = this.GetUserNameIdentifier();
            if (!_userRepo.IsExistingUser(nameIdentifier))
            {
                // New user. Redirect to page for recording user name.
                var queryString = new QueryString { { "returnUrl", returnUrl } };
                return new RedirectResult("/Account/UserData" + queryString);
            }

            // user exists.
            // Redirect back to the page the user was querying.
            return new RedirectResult(returnUrl);
        }
开发者ID:MatsTheSpatz,项目名称:Playground,代码行数:26,代码来源:AccountController.cs

示例4: Creating_from_empty_map

            public void Creating_from_empty_map()
            {
                var args = new Dictionary<string, string>();
                var qs = new QueryString(args);

                qs.ToString().ShouldBe(string.Empty);
            }
开发者ID:ssankar1234,项目名称:stormpath-sdk-dotnet,代码行数:7,代码来源:QueryString_tests.cs

示例5: Process

        public ActionResult Process(HttpRequestBase request, ModelStateDictionary modelState)
        {
            IpnVerificationBinder binder = new IpnVerificationBinder();
            Transaction tx = binder.Bind(request.Form, modelState);

            ContentResult cr = new ContentResult();
            cr.ContentEncoding = Encoding.UTF8;
            cr.ContentType = "text/html";
            cr.Content = "INVALID";

            if (tx != null)
            {
                Transaction dbTx = m_txRepository.GetAll().Where(x => x.Tx == tx.Tx).FirstOrDefault();
                if (dbTx != null)
                {
                    string expected = dbTx.ToIpnQueryString().ToString();
                    QueryString actualQs = new QueryString();
                    actualQs.Add(request.Form);
                    actualQs.Remove("cmd");
                    string actual = actualQs.ToString();

                    if (expected == actual)
                    {
                        cr.Content = "VERIFIED";
                    }
                }
            }

            return cr;
        }
开发者ID:triggerfish,项目名称:PayPalEmulator,代码行数:30,代码来源:AuthoriseIpnHandler.cs

示例6: Encode

 /// <summary>
 /// Combines the given URI components into a string that is properly encoded for use in HTTP headers.
 /// </summary>
 /// <param name="pathBase"></param>
 /// <param name="path"></param>
 /// <param name="query"></param>
 /// <param name="fragment"></param>
 /// <returns></returns>
 public static string Encode(PathString pathBase = new PathString(),
     PathString path = new PathString(),
     QueryString query = new QueryString(),
     FragmentString fragment = new FragmentString())
 {
     string combinePath = (pathBase.HasValue || path.HasValue) ? (pathBase + path).ToString() : "/";
     return combinePath + query + fragment;
 }
开发者ID:Kagamine,项目名称:HttpAbstractions,代码行数:16,代码来源:UriHelper.cs

示例7: MyFact

        public void MyFact()
        {
            var queryString = new QueryString();

            queryString.Add("q", "mcdonald");

            Assert.Equal("q=mcdonald", queryString.ToString());
        }
开发者ID:McDonaldConsulting,项目名称:Utility,代码行数:8,代码来源:QueryStringTests.cs

示例8: AppendOtherObjectsWithCanBeConvertedToStrings

        public void AppendOtherObjectsWithCanBeConvertedToStrings()
        {
            string actual = new QueryString().
                Append("foo", 10).
                Append("bar", "20.00").ToString();

            Assert.AreEqual("foo=10&bar=20.00", actual);
        }
开发者ID:ronin1,项目名称:braintree_dotnet,代码行数:8,代码来源:QueryStringTest.cs

示例9: ParseQueryString_001

        public void ParseQueryString_001()
        {
            var QueryString = new QueryString("abc?a=b");

            Assert.AreEqual(1,   QueryString.Count());
            Assert.AreEqual("a", QueryString.First().Key);
            Assert.AreEqual("b", QueryString.First().Value.First());
        }
开发者ID:Vanaheimr,项目名称:Hermod,代码行数:8,代码来源:QueryStringTests.cs

示例10: With_no_parameters

            public void With_no_parameters()
            {
                var uri = new Uri("http://foo/bar");
                var qs = new QueryString(uri);

                qs.ToString().ShouldBe(string.Empty);
                qs.ToString(canonical: true).ShouldBe(string.Empty);
            }
开发者ID:ssankar1234,项目名称:stormpath-sdk-dotnet,代码行数:8,代码来源:QueryString_tests.cs

示例11: ShouldNotEncodeWhenAdding

        public void ShouldNotEncodeWhenAdding()
        {
            // arrange
            QueryString qs = new QueryString();
            qs.Add("1", "http://");

            // act and assert
            Assert.AreEqual("http://", qs["1"]);
        }
开发者ID:triggerfish,项目名称:Common,代码行数:9,代码来源:QueryStringTests.cs

示例12: ShouldEncodeWhenConvertingToString

        public void ShouldEncodeWhenConvertingToString()
        {
            // arrange
            QueryString qs = new QueryString();
            qs.Add("1", "http://");

            // act and assert
            Assert.AreEqual("?1=http%3a%2f%2f", qs.ToString());
        }
开发者ID:triggerfish,项目名称:Common,代码行数:9,代码来源:QueryStringTests.cs

示例13: ShouldDecodeWhenGettingValue

        public void ShouldDecodeWhenGettingValue()
        {
            // arrange
            QueryString qs = new QueryString();
            qs.Add("1", "http%3a%2f%2f");

            // act and assert
            Assert.AreEqual("http://", qs["1"]);
        }
开发者ID:triggerfish,项目名称:Common,代码行数:9,代码来源:QueryStringTests.cs

示例14: ParseQueryString_002

        public void ParseQueryString_002()
        {
            var QueryString = new QueryString("?a=b&a=c");

            Assert.AreEqual(1, QueryString.Count());
            Assert.AreEqual("a", QueryString.First().Key);
            Assert.AreEqual("b", QueryString.First().Value.First());
            Assert.AreEqual("c", QueryString.First().Value.Skip(1).First());
        }
开发者ID:Vanaheimr,项目名称:Hermod,代码行数:9,代码来源:QueryStringTests.cs

示例15: ShouldBuildHttpPostString

        public void ShouldBuildHttpPostString()
        {
            // arrange
            QueryString qs = new QueryString();
            qs.Add("1", "2");
            qs.Add("3", "4");

            // act and assert
            Assert.AreEqual("1=2&3=4", qs.ToString(HttpAction.Post));
        }
开发者ID:triggerfish,项目名称:Common,代码行数:10,代码来源:QueryStringTests.cs


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